Submission #824490

#TimeUsernameProblemLanguageResultExecution timeMemory
824490tomrukSplit the Attractions (IOI19_split)C++17
40 / 100
98 ms17516 KiB
#include "split.h" #include <bits/stdc++.h> #define N 100005 using namespace std; int par[N]; vector<int> adj[N]; int sub[N]; int n; int find(int a){ if(a == par[a]) return a; return par[a] = find(par[a]); } bool merge(int a,int b){ a = find(a); b = find(b); if(a== b) return 0; par[a] = b; return 1; } int dfs1(int v,int pr){ sub[v] = 1; int ret = v; for(auto u:adj[v]){ if(u == pr)continue; int tmp = dfs1(u,v); sub[v] += sub[u]; if(sub[u] > n/2){ ret = tmp; } } return ret; } vector<int> res; int need; int ban = -1; void dfs2(int v,int pr,int col){ if(!need) return; res[v] = col; need--; for(auto u:adj[v]){ if(u == pr || u == ban)continue; dfs2(u,v,col); } } vector<int> find_split(int _n, int a, int b, int c, vector<int> p, vector<int> q){ n = _n; res.assign(n,0); for(int i = 0;i<n;i++){ par[i] = i; } for(int i = 0;i<p.size();i++){ if(merge(p[i],q[i])){ adj[p[i]].push_back(q[i]); adj[q[i]].push_back(p[i]); } } int cent = dfs1(0,-1); dfs1(cent,-1); vector<int> v = {a,b,c}; vector<int> ord = {0,1,2}; sort(ord.begin(),ord.end(),[&](int a,int b){ return v[a] < v[b]; }); for(auto u:adj[cent]){ if(sub[u] >= v[ord[0]]){ ban = u; need = v[ord[0]]; dfs2(u,cent,1 + ord[0]); break; } } if(ban != -1){ for(int i = 0;i<n;i++){ if(res[i] == 0) res[i] = ord[2] + 1; } need = v[ord[1]]; dfs2(cent,-1,ord[1] + 1); } return res; }

Compilation message (stderr)

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:54:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |  for(int i = 0;i<p.size();i++){
      |                ~^~~~~~~~~
#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...