fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. bool odw[500002];
  4. vector<bool> wyn;
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. bool k=1;
  10. cout<<(k-1)*(-1)<<endl;
  11. int n,m;cin>>n>>m;
  12. vector<vector<int>> vec;
  13. for(int i=0;i<n;i++)
  14. {
  15. vector<int> a;
  16. vec.push_back(a);
  17. }
  18. wyn.resize(n);
  19. for(int i=0;i<m;i++)
  20. {
  21. int a,b;cin>>a>>b;
  22. vec[a-1].push_back(b-1);
  23. vec[b-1].push_back(a-1);
  24. }
  25. queue<pair<int,int>> que;
  26. for(int i=0;i<n;i++)
  27. {
  28. if(odw[i]==1)
  29. continue;
  30. else
  31. {
  32. que.push({i,1});
  33. //cout<<i<<' '<<vec[i].size()<<endl;
  34. if(vec[i].size()==0)
  35. {
  36. cout<<"NIE";
  37. return 0;
  38. }
  39. while(!que.empty())
  40. {
  41. pair<int,bool> a=que.front();
  42. que.pop();
  43. odw[a.first]=1;
  44. wyn[a.first]=a.second;
  45. for(auto x:vec[a.first])
  46. {
  47. if(odw[x]==0)
  48. {
  49. pair<int,bool> par={x,(a.second-1)*(-1)};
  50. que.push(par);
  51. }
  52. }
  53. }
  54.  
  55. }
  56. }
  57. cout<<"TAK";
  58. for(auto x:wyn)
  59. {
  60. if(x)
  61. {
  62. cout<<endl<<'K';
  63. }
  64. else
  65. cout<<endl<<'S';
  66. }
  67. }
Success #stdin #stdout 0s 5316KB
stdin
3 3
2 1
2 3
1 3
stdout
0
TAK
K
S
K