Submission #472895

#TimeUsernameProblemLanguageResultExecution timeMemory
472895aris12345678Connecting Supertrees (IOI20_supertrees)C++14
0 / 100
1 ms204 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; const int mxN = 1005; int par[mxN], siz[mxN]; vector<int> adj[mxN]; bool vis[mxN]; /* void build(vector<vector<int> > b) { int n = int(b.size()); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) cout << b[i][j] << " "; cout << "\n"; } } */ void make_set(int x) { par[x] = x, siz[x] = 1; } int find_set(int x) { return x == par[x] ? x : par[x] = find_set(par[x]); } bool union_sets(int a, int b) { a = find_set(a), b = find_set(b); if(a == b) return false; if(siz[a] < siz[b]) swap(a, b); par[b] = a, siz[a] += siz[b]; return true; } int construct(vector<vector<int> > p) { int n = int(p.size()); for(int i = 0; i < n; i++) make_set(i); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(p[i][j] == 2) { if(union_sets(i, j)) { int parent = find_set(i); if(parent == i) adj[parent].push_back(j); else if(parent == j) adj[parent].push_back(i); else { adj[parent].push_back(i); adj[parent].push_back(j); } } } } } for(int i = 0; i < n; i++) { if(siz[find_set(i)] <= 2) return 0; for(int j = 0; j < n; j++) { if(p[i][j] == 0 && find_set(i) == find_set(j)) return 0; } } vector<vector<int> > b(n, vector<int>(n, 0)); for(int i = 0; i < n; i++) { int parent = find_set(i); if(parent == i) continue; b[i][parent] = b[parent][i] = 1; if(!vis[parent]) { b[adj[parent][0]][adj[parent][1]] = b[adj[parent][1]][adj[parent][0]] = 1; vis[parent] = true; } } build(b); return 1; } /* int main() { int n; scanf("%d", &n); vector<vector<int> > p(n, vector<int>(n)); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) scanf("%d", &p[i][j]); } cout << "\n"; printf("%d\n", construct(p)); return 0; } */
#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...