Submission #1014119

#TimeUsernameProblemLanguageResultExecution timeMemory
10141190npataConnecting Supertrees (IOI20_supertrees)C++17
100 / 100
150 ms24240 KiB
#include "supertrees.h" #include<bits/stdc++.h> using namespace std; #define vec vector int construct(vec<vec<int>> p) { int n = p.size(); vec<vec<int>> edges(n, vec<int>(n, 0)); vec<int> comp(n, -1); for(int i = 0; i<n; i++) { if(comp[i] != -1) continue; for(int j = i; j<n; j++) { if(p[i][j] > 0) comp[j] = i; } } for(int i = 0; i<n; i++) { for(int j = 0; j<n; j++) { if(((p[i][j] > 0) != (comp[i] == comp[j])) || p[i][j] == 3) { return 0; } } } vec<set<int>> comp_cycle(n); vec<int> cycle_chains(n, -1); for(int i = 0; i<n; i++) { for(int j = 0; j<n; j++) { if(p[i][j] == 1) { cycle_chains[i] = j; comp_cycle[comp[i]].insert(j); break; } } } for(int i = 0; i<n; i++) { for(int j = 0; j<n; j++) { if(comp[i] != comp[j]) continue; if((cycle_chains[i] == cycle_chains[j]) != (p[i][j] == 1)) { return 0; } } } for(int i = 0; i<n; i++) { if(comp[i] != i) continue; assert(comp_cycle[i].size() > 0); if(comp_cycle[i].size() == 2) return 0; if(comp_cycle[i].size() == 1) continue; int prev = *comp_cycle[i].rbegin(); for(int u : comp_cycle[i]) { edges[prev][u] = 1; edges[u][prev] = 1; prev = u; } } for(int i = 0; i<n; i++) { for(int j = i-1; j>=0; j--) { if(cycle_chains[i] != -1 && cycle_chains[i] == cycle_chains[j]) { edges[i][j] = 1; edges[j][i] = 1; break; } } } 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...