제출 #524292

#제출 시각아이디문제언어결과실행 시간메모리
524292Turkhuu슈퍼트리 잇기 (IOI20_supertrees)C++17
21 / 100
214 ms26112 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; struct dsu{ int n; vector<int> size, parent; dsu(int _n) : n(_n), size(n, 1), parent(n){ iota(parent.begin(), parent.end(), 0); } int get(int a){ return a == parent[a] ? a : parent[a] = get(parent[a]); } bool unite(int b, int a){ a = get(a); b = get(b); if(a == b){ return 0; } size[b] += size[a]; parent[a] = b; return 1; } }; int construct(vector<vector<int>> a){ int n = (int)a.size(); vector<vector<int>> ans(n, vector<int>(n, 0)); vector<vector<int>> v1(n), v2(n); for(int i = 0; i < n; i++){ for(int j = i + 1; j < n; j++){ if(a[i][j] == 1){ v1[i].push_back(j); v1[j].push_back(i); } else if(a[i][j] == 2){ v2[i].push_back(j); v2[j].push_back(i); } else if(a[i][j] == 3){ return 0; } } } dsu s(n); for(int i = 0; i < n; i++){ if(s.parent[i] == i){ for(int j = 0; j < n; j++){ for(int k : v1[i]){ if(a[k][j] != a[i][j]){ return 0; } ans[i][k] = 1; ans[k][i] = 1; s.unite(i, k); } } } } vector<bool> b(n, false); for(int i = 0; i < n; i++){ if(b[s.parent[i]]){ continue; } b[i] = true; int cur = i; for(int j : v2[i]){ if(s.parent[j] != j){ if(a[i][s.parent[j]] != 2){ return 0; } continue; } for(int k : v2[j]){ if(a[i][k] == 0 || (a[i][k] == 1 && s.parent[k] != i) || (a[i][k] == 2 && s.parent[k] == i)){ return 0; } } ans[cur][i] = 1; ans[i][cur] = 1; b[j] = true; cur = j; } if(cur == i){ continue; } if(ans[i][cur]){ return 0; } ans[i][cur] = 1; ans[cur][i] = 1; } build(ans); 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...