Submission #1311836

#TimeUsernameProblemLanguageResultExecution timeMemory
1311836michael12Connecting Supertrees (IOI20_supertrees)C++20
0 / 100
100 ms22204 KiB
#include "supertrees.h" #include<bits/stdc++.h> #define ff first #define ss second #define pb push_back #define mp make_pair using namespace std; const int maxn = 1e3 + 10; vector<int> cnt[maxn]; struct DSU { vector<int> pt, sz; DSU(int sz0) { pt.resize(sz0); sz.resize(sz0, 1); for (int i = 0; i < sz0; i++) pt[i] = i; } int find(int x) { if (x == pt[x]) return x; return pt[x] = find(pt[x]); } void unite(int u, int v) { int a = find(u), b = find(v); if (a != b) { if (sz[a] < sz[b]) swap(a, b); pt[b] = a; sz[a] += sz[b]; for (auto x : cnt[b]) cnt[a].push_back(x); cnt[b].clear(); } } bool smcomp(int u, int v) { return find(u) == find(v); } }; int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int>> T(n, vector<int>(n, 0)); for (int i = 0; i < n; i++) cnt[i].clear(), cnt[i].push_back(i); DSU dsu(n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (p[i][j] == 1 && dsu.find(i) != dsu.find(j)) { dsu.unite(i, j); T[i][j] = T[j][i] = 1; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (p[i][j] != 1 && dsu.find(i) == dsu.find(j)){ return 0; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (p[i][j] == 3 || (p[i][j] == 0 && dsu.find(i) == dsu.find(j))){ return 0; } } } for (int i = 0; i < n; i++){ cnt[i].clear(); } for (int i = 0; i < n; i++){ cnt[dsu.find(i)].push_back(i); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (p[i][j] == 2 && dsu.find(i) != dsu.find(j)){ dsu.unite(i, j); } } } for (int i = 0; i < n; i++) { if (cnt[i].size() < 2) continue; if (cnt[i].size() == 2) return 0; for (int j = 0; j < (int)cnt[i].size(); j++) { int u = cnt[i][j]; int v = cnt[i][(j + 1) % cnt[i].size()]; T[u][v] = T[v][u] = 1; } } build(T); 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...