Submission #400681

#TimeUsernameProblemLanguageResultExecution timeMemory
400681teehandsomeConnecting Supertrees (IOI20_supertrees)C++17
21 / 100
259 ms28128 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; for(int i=0;i<sz;i++) { for(int j=0;j<sz;j++) { int u=group[root][i]; int v=group[root][j]; if(p[u][v]!=1) return false; } } for(int i=0;i<sz-1;i++) { int u=group[root][i]; int v=group[root][i+1]; adj[u][v]=adj[v][u]=1; } 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; } } 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...