Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- vector<int> adj[10005];
- int NUMB, n;
- int vis[10005];
- bool dfs(int v)
- {
- vis[v] = 1;
- for (auto u: adj[v])
- {
- if (vis[u] == 1)
- {
- return false;
- }
- if (vis[u] == 0 && !dfs(u))
- {
- return false;
- }
- }
- vis[v] = 2;
- return true;
- }
- bool cmp(int a, int b)
- {
- if (NUMB == 10000) return a < b;
- cout << "1 " << a << " " << b << "\n";
- cout.flush();
- string ans; cin >> ans;
- ++ NUMB;
- if (ans[0] == 'Y')
- {
- adj[a].push_back(b);
- for (int i = 1; i <= n; ++ i) vis[i] = 0;
- for (int i = 1; i <= n; ++ i)
- {
- if (!vis[i])
- {
- if (!dfs(i))
- {
- cout<<"0 ";
- for (int j = 1; j <= n; ++ j)
- {
- cout << "0 ";
- }
- cout << "\n";
- cout.flush();
- exit(0);
- }
- }
- }
- return true;
- }
- else
- {
- adj[b].push_back(a);
- for (int i = 1; i <= n; ++ i) vis[i]=0;
- for (int i = 1; i <= n; ++ i)
- {
- if (!vis[i])
- {
- if (!dfs(i))
- {
- cout<<"0 ";
- for (int j = 1; j <= n; ++ j)
- {
- cout << "0 ";
- }
- cout << "\n";
- cout.flush();
- exit(0);
- }
- }
- }
- return false;
- }
- }
- int main()
- {
- cin >> n;
- vector<int> v;
- for (int i = 1; i <= n; ++ i)
- {
- v.push_back(i);
- }
- srand(1031999); random_shuffle(v.begin(), v.end());
- sort(v.begin(), v.end(), cmp);
- if (NUMB == 10000)
- {
- for (int i = 1; i <= n; ++ i) vis[i]=0;
- for (int i = 1; i <= n; ++ i)
- {
- if (!vis[i])
- {
- if (!dfs(i))
- {
- cout<<"0 ";
- for (int j = 1; j <= n; ++ j)
- {
- cout << "0 ";
- }
- cout << "\n";
- cout.flush();
- exit(0);
- }
- }
- }
- }
- cout << "0 ";
- for (int i = 0; i < (int) v.size(); ++ i)
- {
- cout << v[i] << " ";
- }
- cout << "\n";
- cout.flush();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement