제출 #472868

#제출 시각아이디문제언어결과실행 시간메모리
472868aris12345678슈퍼트리 잇기 (IOI20_supertrees)C++14
21 / 100
269 ms24004 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; const int mxN = 1005; int par[mxN], siz[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] == 1) { union_sets(i, j); // cout << i << " " << j << "\n"; } } } for(int i = 0; i < n; i++) { 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; } 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...