Submission #953785

#TimeUsernameProblemLanguageResultExecution timeMemory
953785Trisanu_DasConnecting Supertrees (IOI20_supertrees)C++17
100 / 100
188 ms24148 KiB
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; int n, par[1005], ls[1005]; vector<vector<int> > b; int find(int u){ if(par[u] == u) return u; par[u] = find(par[u]); return par[u]; } void union_(int u, int v){ u = find(u); v = find(v); if(u == v) return; par[u] = v; b[u][ls[v]] = b[ls[v]][u] = 1; ls[v] = ls[u]; } int construct(vector<vector<int> > p){ n = p.size(); b.assign(n, vector<int>(n, 0)); iota(par, par + n, 0); iota(ls, ls + n, 0); for(int i = 0; i < n; i++) { for(int j = i + 1; j < n; j++) { if(p[i][j] == 3) return 0; if(p[i][j] == 1) union_(i, j); } } for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) if(p[i][j] != 1 && find(i) == find(j)) return 0; iota(ls, ls + n, 0); for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) if(p[i][j] == 2) union_(i, j); for(int i = 0; i < n; i++){ if(par[i] == i && ls[i] != i){ if(b[ls[i]][i] == 1) return 0; b[ls[i]][i] = b[i][ls[i]] = 1; } } for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) if(find(i) == find(j) && p[i][j] == 0) return 0; build(b); 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...