# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
410040 | 2021-05-21T21:37:26 Z | dreezy | Simurgh (IOI17_simurgh) | C++17 | 15 ms | 292 KB |
#include <bits/stdc++.h> #include "simurgh.h" using namespace std; struct UnionFind{ vector<int> height, parent; void init(int n){ height.assign(n, 0); parent.assign(n,0); for(int i =0; i<n;i++) parent[i] = i; } int getRoot(int n){ if(parent[n] != n) return parent[n] = getRoot(parent[n]); return parent[n]; } bool isSame(int n1, int n2){ return getRoot(n1) == getRoot(n2); } void join(int n1, int n2){ int r1 = getRoot(n1); int r2 = getRoot(n2); if(height[r1] > height[r2]){ parent[r2] = r1; height[r1] = max(height[r1], height[r2]+1); } else{ parent[r1] = r2; height[r2] = max(height[r2], height[r1]+1); } } }; vector<int> find_roads(int n, vector<int> u, vector<int> v ){ vector<int> is_royal; int m = u.size(); set<int> dontknow; for(int i =0; i< m; i++) dontknow.insert(i); ///////// while(true){ int curcheck = -1; int prevans = -1; int prevcheck = -1; UnionFind uf; uf.init(n); vector<int> roads; for(int i : is_royal){ uf.join(u[i], v[i]); roads.push_back(i); } for(int i : dontknow){ if(!uf.isSame(u[i], v[i]) && prevcheck != i){ uf.join(u[i], v[i]); roads.push_back(i); curcheck = i; if(roads.size() == n-1) break; } } int ans = count_common_roads(roads); if(ans == n-1) return roads; if(prevans == -1){ prevans = ans; continue; } if(ans == prevans+1){ dontknow.erase(prevcheck); is_royal.push_back(prevcheck); } else if(ans==prevans -1){ dontknow.erase(prevcheck); } prevcheck = curcheck; } return vector<int>(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 204 KB | WA in grader: NO |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 204 KB | WA in grader: NO |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 204 KB | WA in grader: NO |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | correct |
2 | Incorrect | 9 ms | 292 KB | WA in grader: NO |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 204 KB | WA in grader: NO |
2 | Halted | 0 ms | 0 KB | - |