Submission #400669

#TimeUsernameProblemLanguageResultExecution timeMemory
400669teehandsomeConnecting Supertrees (IOI20_supertrees)C++17
11 / 100
245 ms26020 KiB
#include "supertrees.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define endl '\n' #define INF 1e9+7 #define all(x) x.begin(),x.end() using namespace std; using namespace __gnu_pbds; using ll=long long; using pii=pair<int,int>; using ppi=pair<int,pii>; using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>; template<typename T> void _print(vector<T> x) {cerr<<"{"; for(auto e:x) cerr<<e<<","; cerr<<"}";} void _print(pii x) {cerr<<"{"<<x.first<<","<<x.second<<"}";} template<typename T> void _print(T x) {cerr<<x;} void dbg() {cerr<<endl;} template<typename Head,typename... Tail> void dbg(Head H,Tail... T) { _print(H); if(sizeof...(T)) cerr<<","; else cerr<<"\"]"; dbg(T...); } #define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__) const int mxn=1003; vector<vector<int>> adj,p; vector<int> group[mxn]; int n; vector<int> par; int findp(int x) { while(par[x]!=x) par[x]=par[par[x]],x=par[x]; return x; } void unionset(int u,int v) { int U=findp(u),V=findp(v); par[U]=V; } bool solve(int root) { int sz=group[root].size(); if(sz==1) return true; vector<int> two,one,mix; for(int i=0;i<sz;i++) { bool isone=false,istwo=false; for(int j=0;j<sz;j++) { if(j==i) continue; if(p[i][j]==0) return false; else if(p[i][j]==1) isone=true; else if(p[i][j]==2) istwo=true; } if(isone and !istwo) one.push_back(group[root][i]); else if(isone and istwo) mix.push_back(group[root][i]); else two.push_back(group[root][i]); } int l1=one.size(); int l2=two.size(); int l12=mix.size(); if(l1 and (l2 or l12)) return false; if(l1) { for(int i=0;i<l1-1;i++) { int u=one[i]; int v=one[i+1]; adj[u][v]=adj[v][u]=1; } return true; } if(!l12) { for(int i=0;i<l2;i++) { int u=two[i]; int v=two[(i+1)%l2]; adj[u][v]=adj[v][u]=1; } return true; } // !l1 and l2 and l12 assert(!l1 and l2 and l12); for(int i=0;i<l2-1;i++) { int u=two[i]; int v=two[i+1]; adj[u][v]=adj[v][u]=1; } for(int i=0;i<l12-1;i++) { int u=mix[i]; int v=mix[i+1]; adj[u][v]=adj[v][u]=1; } int u=mix[l12-1]; adj[u][two[0]]=adj[two[0]][u]=1; adj[u][two[l2-1]]=adj[two[l2-1]][u]=1; // debug(one); // debug(two); // debug(mix); return true; } int construct(std::vector<std::vector<int>> P) { p=P; n=p.size(); par.resize(n); iota(all(par),0); // debug(par); adj.resize(n,vector<int>(n,0)); for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(p[i][j]!=0) { unionset(i,j); } } } for(int i=0;i<n;i++) { par[i]=findp(par[i]); } for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(p[i][j]>2) return 0; // if(!p[i][j]) { // if(par[i]==par[j]) return 0; // } // else { // if(par[i]!=par[j]) return 0; // } } } for(int i=0;i<n;i++) { par[i]=findp(par[i]); group[par[i]].push_back(i); } vector<bool> flag(n+1,false); for(int i=0;i<n;i++) { if(flag[par[i]]) continue; flag[par[i]]=true; bool ok=solve(par[i]); if(!ok) return 0; } for(int i=0;i<n;i++) adj[i][i]=0; build(adj); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int findp(int)':
supertrees.cpp:38:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   38 |     while(par[x]!=x) par[x]=par[par[x]],x=par[x]; return x;
      |     ^~~~~
supertrees.cpp:38:51: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   38 |     while(par[x]!=x) par[x]=par[par[x]],x=par[x]; return x;
      |                                                   ^~~~~~
#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...