Submission #576130

#TimeUsernameProblemLanguageResultExecution timeMemory
576130MadokaMagicaFanConnecting Supertrees (IOI20_supertrees)C++14
96 / 100
211 ms22248 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pi = pair<int,int>; #define all(v) v.begin(),v.end() #define sort(v) sort(all(v)) #define endl '\n' #define forn(i,n) for(int i = 0; i < n; ++i) #define forbe(i,b,e) for(int i = b; i < e; ++i) #define forr(i,n) for(int i = n-1; i >= 0; --i) #define sz(v) ((int)v.size()) #define pb push_back #define f first #define s second void build(vector<vi> b); const int N = 1e3; int par[N]; int lst[N]; int siz[N]; int lastpar[N]; vi adj[N]; int getp(int x) { return par[x] = (par[x] == x ? x : getp(par[x])); } int getl(int x) { return lst[x] = (lst[x] == x ? x : getl(lst[x])); } int uni(int a, int b) { a = getp(a); b = getp(b); int c = getl(a); int d = getl(b); if (a == b) return 0; adj[a].pb(d); adj[d].pb(a); par[a] = b; lst[d] = c; siz[b] += siz[a]; return 1; } int construct(vector<vi> p) { int n = sz(p); bool t0, t1, t2; t0 = t1 = t2 = 0; int task = 0; forn(i,n) { forn(j,n) { if (i == j) continue; if (p[i][j] == 0) t0 = 1; if (p[i][j] == 1) t1 = 1; if (p[i][j] == 2) t2 = 1; } } if (t1 && !t2) task = 1; if (t2 && !t1) task = 2; if (t2 && t1) task = 3; forn(i,n) par[i] = i; forn(i,n) lst[i] = i; forn(i,n) siz[i] = 1; vector<vi> ans(n); forn(i,n) ans[i].assign(n,0); if (task < 3) { forn(i,n) { forn(j,n) { if (i == j) continue; if (p[i][j]) uni(i,j); } } forn(i,n) { forn(j,n) { if (i == j) continue; if (p[i][j] == 0 && getp(i) == getp(j)) return 0; } } if (task == 2) { forn (i, n) { if (getp(i) != i) continue; if (siz[i] == 2) return 0; if (siz[i] == 1) continue; adj[i].pb(getl(i)); adj[getl(i)].pb(i); } } } else { forn(i,n) { forn(j,n) { if (i == j) continue; if (p[i][j] == 1) uni(i,j); } } forn(i,n) { lastpar[i] = getp(i); if (getp(i) != i) continue; lst[i] = i; siz[i] = 1; } forn(i,n) { forn(j,n) { if (i == j) continue; if (p[i][j] == 2) uni(i,j); } } forn (i, n) { if (getp(i) != i) continue; if (siz[i] == 2) return 0; if (siz[i] == 1) continue; adj[i].pb(getl(i)); adj[getl(i)].pb(i); } forn(i,n) { forn(j,n) { if (p[lastpar[i]][lastpar[j]] == 2 && p[i][j] != 2) return 0; if (i == j) continue; if (p[i][j] == 0 && getp(i) == getp(j)) return 0; if (p[i][j] >= 1 && getp(i) != getp(j)) return 0; } } } forn (i,n) { for (int u : adj[i]) ans[i][u] = 1; } build(ans); return 1; } #ifdef ONPC void build(vector<vi> b) { } void solve() { } int main() { // freopen("in", "r", stdin); // ios_base::sync_with_stdio(0);cin.tie(0); solve(); } #endif

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:53:10: warning: variable 't0' set but not used [-Wunused-but-set-variable]
   53 |     bool t0, t1, t2;
      |          ^~
#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...