Submission #891510

#TimeUsernameProblemLanguageResultExecution timeMemory
891510Sir_Ahmed_ImranSplit the Attractions (IOI19_split)C++17
7 / 100
642 ms1048576 KiB
///~~~LOTA~~~/// #include <bits/stdc++.h> using namespace std; #define nl '\n' #define ff first #define ss second #define ll long long #define append push_back #define pii pair<int,int> #define all(x) (x).begin(),(x).end() #define N 100001 vector<int> color; vector<int> e[N]; int s[N]; int A[N]; int B[N]; int C[N]; int y,z; void dfs(int v,int u,int a,int b,int c){ s[v]=1; for(auto& i:e[v]){ if(i==u) continue; dfs(i,v,a,b,c); s[v]+=s[i]; if(A[i]) A[v]=1; if(B[i]) B[v]=1; if(C[i]) C[v]=1; } if(s[v]==a) A[v]=1; if(s[v]==b) B[v]=1; if(s[v]==c) C[v]=1; } void Color(int v,int u,int a,int b,int c){ if(!z){ if(A[v] && s[v]==a+b) z=3; if(B[v] && s[v]==a+b) z=3; if(A[v] && s[v]==a+c) z=2; if(C[v] && s[v]==a+c) z=2; if(B[v] && s[v]==c+b) z=1; if(C[v] && s[v]==c+b) z=1; if(z) color[v]=4; } if(color[v]==4 && s[v]==a && z!=1 && !y){ color[v]=1; y=5-z; } if(color[v]==4 && s[v]==b && z!=2 && !y){ color[v]=2; y=4-z; } if(color[v]==4 && s[v]==c && z!=3 && !y){ color[v]=3; y=3-z; } for(auto& i:e[v]){ if(i==u) continue; color[i]=color[v]; Color(i,v,a,b,c); } } vector<int> find_split(int n,int a,int b,int c,vector<int> p,vector<int> q){ for(int i=y=z=0;i<n-1;i++){ e[p[i]].append(q[i]); e[q[i]].append(p[i]); } for(int i=0;i<n;i++) color.append(0); dfs(0,-1,a,b,c); Color(0,-1,a,b,c); if(!z){ dfs(1,-1,a,b,c); Color(1,-1,a,b,c); } for(int i=0;i<n;i++){ if(color[i]==0) color[i]=z; if(color[i]==4) color[i]=y; } return color; }
#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...