Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<int> adj[10005];
  5. int NUMB, n;
  6.  
  7. int vis[10005];
  8.  
  9. bool dfs(int v)
  10. {
  11. vis[v] = 1;
  12. for (auto u: adj[v])
  13. {
  14. if (vis[u] == 1)
  15. {
  16. return false;
  17. }
  18. if (vis[u] == 0 && !dfs(u))
  19. {
  20. return false;
  21. }
  22. }
  23. vis[v] = 2;
  24. return true;
  25. }
  26.  
  27.  
  28. bool cmp(int a, int b)
  29. {
  30. if (NUMB == 10000) return a < b;
  31.  
  32. cout << "1 " << a << " " << b << "\n";
  33. cout.flush();
  34.  
  35. string ans; cin >> ans;
  36.  
  37. ++ NUMB;
  38.  
  39. if (ans[0] == 'Y')
  40. {
  41. adj[a].push_back(b);
  42.  
  43. for (int i = 1; i <= n; ++ i) vis[i] = 0;
  44. for (int i = 1; i <= n; ++ i)
  45. {
  46. if (!vis[i])
  47. {
  48. if (!dfs(i))
  49. {
  50. cout<<"0 ";
  51. for (int j = 1; j <= n; ++ j)
  52. {
  53. cout << "0 ";
  54. }
  55. cout << "\n";
  56. cout.flush();
  57.  
  58. exit(0);
  59. }
  60. }
  61. }
  62.  
  63.  
  64. return true;
  65. }
  66. else
  67. {
  68. adj[b].push_back(a);
  69.  
  70. for (int i = 1; i <= n; ++ i) vis[i]=0;
  71. for (int i = 1; i <= n; ++ i)
  72. {
  73. if (!vis[i])
  74. {
  75. if (!dfs(i))
  76. {
  77. cout<<"0 ";
  78. for (int j = 1; j <= n; ++ j)
  79. {
  80. cout << "0 ";
  81. }
  82. cout << "\n";
  83. cout.flush();
  84.  
  85. exit(0);
  86. }
  87. }
  88. }
  89. return false;
  90. }
  91. }
  92. int main()
  93. {
  94. cin >> n;
  95.  
  96. vector<int> v;
  97. for (int i = 1; i <= n; ++ i)
  98. {
  99. v.push_back(i);
  100. }
  101.  
  102. srand(1031999); random_shuffle(v.begin(), v.end());
  103. sort(v.begin(), v.end(), cmp);
  104.  
  105. if (NUMB == 10000)
  106. {
  107. for (int i = 1; i <= n; ++ i) vis[i]=0;
  108. for (int i = 1; i <= n; ++ i)
  109. {
  110. if (!vis[i])
  111. {
  112. if (!dfs(i))
  113. {
  114. cout<<"0 ";
  115. for (int j = 1; j <= n; ++ j)
  116. {
  117. cout << "0 ";
  118. }
  119. cout << "\n";
  120. cout.flush();
  121.  
  122. exit(0);
  123. }
  124. }
  125. }
  126. }
  127.  
  128. cout << "0 ";
  129. for (int i = 0; i < (int) v.size(); ++ i)
  130. {
  131. cout << v[i] << " ";
  132. }
  133. cout << "\n";
  134. cout.flush();
  135.  
  136. return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement