Submission #421997

#TimeUsernameProblemLanguageResultExecution timeMemory
421997OttoTheDinoConnecting Supertrees (IOI20_supertrees)C++17
100 / 100
254 ms24044 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; #define rep(i,s,e) for (int i = s; i <= e; ++i) #define rrep(i,s,e) for (int i = s; i >= e; --i) #define pb push_back #define pf push_front #define fi first #define se second #define all(a) a.begin(), a.end() typedef long long ll; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<double> vd; typedef vector<string> vs; typedef vector<char> vc; typedef vector<ll> vll; int construct (vector<vi> p) { int n = p.size(); int sup[n], tree[n], spec[n]; memset(sup,-1,4*n), memset(tree,-1,4*n); rep (i,0,n-1) { if (sup[i]==-1) { bool two = 0; rep (j,0,n-1) { if (p[i][j]==3) return 0; if (p[i][j]==1 || p[i][j]==2) { if (sup[i]==-1) sup[i] = sup[j] = j; else sup[j] = sup[i]; if (p[i][j]==1) { if (tree[i]==-1) tree[i] = tree[j] = j; else tree[j] = tree[i]; } else two = 1; } else if (i==j) return 0; } spec[sup[i]] = !two; } else if (tree[i]==-1) { rep (j,0,n-1) { if (p[i][j]==3) return 0; if (p[i][j]==1 || p[i][j]==2) { if (p[sup[i]][j] != 1 && p[sup[i]][j] != 2) return 0; if (p[i][j]==1) { if (tree[i]==-1) tree[i] = tree[j] = j; else tree[j] = tree[i]; } } else if (p[sup[i]][j]) return 0; } } else rep (j,0,n-1) if (p[tree[i]][j]!=p[i][j]) return 0; } vector<vi> b(n,vi(n,0)); rep (i,0,n-1) { if (i==sup[i]) { int last = i, cnt = 0; rep (j,0,n-1) { if (sup[j]==i && j==tree[j]) cnt++; if (i==j || sup[j]!=i) continue; if (j==tree[j]) { if (spec[i]) continue; b[j][last] = b[last][j] = 1; last = j; } else b[j][tree[j]] = b[tree[j]][j] = 1; } if (last!=i && !spec[i]) b[last][i] = b[i][last] = 1; if (!spec[i] && cnt==2) return 0; } } build(b); 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...