Submission #472898

#TimeUsernameProblemLanguageResultExecution timeMemory
472898aris12345678Connecting 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]; /* 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]); } void union_sets(int a, int b) { a = find_set(a), b = find_set(b); if(a == b) return; if(siz[a] < siz[b]) swap(a, b); par[b] = a, siz[a] += siz[b]; } 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) union_sets(i, 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; } } for(int i = 0; i < n; i++) adj[find_set(i)].push_back(i); vector<vector<int> > b(n, vector<int>(n, 0)); for(int i = 0; i < n; i++) { for(int j = 0; j < int(adj[i].size()); j++) b[adj[i][j]][adj[i][j+1]] = b[adj[i][j+1]][adj[i][j]] = 1; b[adj[i][0]][adj[i][int(adj[i].size())-1]] = b[adj[i][int(adj[i].size())-1]][adj[i][0]] = 1; } 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...