Submission #536379

#TimeUsernameProblemLanguageResultExecution timeMemory
536379ddy888Connecting Supertrees (IOI20_supertrees)C++17
0 / 100
1 ms340 KiB
#undef _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define fi first #define si second #define ar array typedef pair<int,int> pi; typedef tuple<int,int,int> ti; void debug_out() {cerr<<endl;} template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr<<" "<<to_string(H);debug_out(T...);} #define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__) #include "supertrees.h" int N; int A[1010][1010]; vector<vector<int> > ans; vector<int> adj[1010]; struct dsu { int par[1010]; void init(int x) {for (int i = 0; i <= x; ++i) par[i] = i;} int root(int x) { return (par[x]==x)? x:par[x]=root(par[x]); } bool same(int a, int b) { return root(a) == root(b); } void merge(int a, int b) { // b absorbs a if (same(a, b)) return; par[root(a)] = root(b); } }; void join(int x, int y) { ans[x - 1][y - 1] = 1; ans[y - 1][x - 1] = 1; } int construct(std::vector<std::vector<int>> p) { N = p.size(); ans.resize(N, vector<int>(N)); dsu one, two; one.init(N), two.init(N); for (int i = 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) { A[i][j] = p[i - 1][j - 1]; if (i == j) continue; if (A[i][j] == 3) return 0; if (A[i][j] == 2) two.merge(i, j); } } for (int i = 1; i <= N; ++i) adj[two.root(i)].pb(i); for (int i = 1; i <= N; ++i) { if (adj[i].size() <= 2) return 0; int p = -1; for (auto j: adj[i]) { if (p != -1) join(p, j); p = j; } join(adj[i][0], adj[i][adj[i].size() - 1]); for (auto j: adj[i]) { for (auto k: adj[i]) { if (j == k) continue; if (A[j][k] != 2) return 0; } } } for (int i = 1; i <= N; ++i) { for (int j = i + 1; j <= N; ++i) { if (A[i][j] == 1) { one.merge(i, j); join(i, j); } } } for (int i= 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) { if (A[i][j] == 0 && (one.same(i, j) || two.same(i, j))) return 0; } } 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...