Submission #671879

#TimeUsernameProblemLanguageResultExecution timeMemory
671879a_aguiloConnecting Supertrees (IOI20_supertrees)C++14
0 / 100
1098 ms12528 KiB
#include<bits/stdc++.h> #include "supertrees.h" using namespace std; int n; vector<int> father; int root(int node){ if(father[node] == node) return node; return father[node] = root(father[node]); } int merge(int NodeA, int NodeB, vector<vector<int>> p){ int rootA = root(NodeA); int rootB = root(NodeB); if(rootB == rootA) return 1; father[rootA] = rootB; for(int i = 0; i < n; ++i){ if(i == rootA or i == rootB)continue; if(!(((p[rootA][i]) and (p[rootB][i])) or ((!p[rootA][i]) and (!p[rootB][i])))) return 0; } return 1; } int construct(vector<vector<int>> p){ n = p[0].size(); father = vector<int>(n); for(int i = 0; i < n; ++i) { father[i] = i; } for(int i = 0; i < n; ++i){ for(int j = i+1; j < n; ++j){ if(p[i][j]){ int sol = merge(i, j, p); if(!sol) return 0; }else{ for(int k = 0; k < n; ++k){ if(k == i or k==j) continue; if(p[i][k] and p[j][k]) return 0; } } } } vector<vector<int>> edges(n, vector<int>(n, 0)); for(int i = 0; i < n; ++i) { int MyRoot = root(i); if(MyRoot==i) continue; edges[MyRoot][i] = edges[i][MyRoot] = 1; } build(edges); return 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...