Submission #415278

#TimeUsernameProblemLanguageResultExecution timeMemory
415278peuchSplit the Attractions (IOI19_split)C++17
22 / 100
157 ms21508 KiB
#include "split.h" #include<bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int n; int t; int pre[MAXN], low[MAXN]; int sub[MAXN]; vector<int> ar[MAXN]; int marcPA[MAXN]; vector<int> pa; vector<pair<int, int> > comp[MAXN]; int cnt; vector<int> ans; void dfs(int cur, int pai); void paint(int cur, int cor); vector<int> find_split(int N, int a, int b, int c, vector<int> p, vector<int> q) { n = N; ans = vector<int> (n); for(int i = 0; i < p.size(); i++){ ar[p[i]].push_back(q[i]); ar[q[i]].push_back(p[i]); } dfs(0, 0); int cor1; int cor2; int cor3; int val1; int val2; int val3; if(a <= b && a <= c){ cor1 = 1; val1 = a; if(b <= c) cor2 = 2, cor3 = 3, val2 = b, val3 = c; else cor2 = 3, cor3 = 2, val2 = c, val3 = b; } else if(b <= a && b <= c){ cor1 = 2; val1 = b; if(a <= c) cor2 = 1, cor3 = 3, val2 = a, val3 = c; else cor2 = 3, cor3 = 1, val2 = c, val3 = a; } else{ cor1 = 3; val1 = c; if(a <= b) cor2 = 1, cor3 = 2, val2 = a, val3 = b; else cor2 = 2, cor3 = 1, val2 = b, val3 = a; } bool flag = true; for(int i = 0; i < pa.size(); i++){ int cur = pa[i]; sort(comp[cur].begin(), comp[cur].end()); if(comp[cur].back().first < val2) continue; if(n - comp[cur].back().first < val1) continue; ans[cur] = cor1; ans[comp[cur].back().second] = cor2; cnt = val1; paint(cur, cor1); cnt = val2; paint(comp[cur].back().second, cor2); flag = false; break; } if(flag) return ans; for(int i = 0; i < n; i++) if(ans[i] == 0) ans[i] = cor3; return ans; } void dfs(int cur, int pai){ pre[cur] = low[cur] = ++t; sub[cur] = 1; for(int i = 0; i < ar[cur].size(); i++){ int viz = ar[cur][i]; if(viz == pai) continue; if(pre[viz] != 0) low[cur] = min(low[cur], pre[viz]); else{ dfs(viz, cur); if(low[viz] >= pre[cur]){ if(cur != pai || sub[viz] != n - 1){ if(!marcPA[cur]){ pa.push_back(cur); marcPA[cur] = 1; } comp[cur].push_back(make_pair(sub[viz], viz)); } } low[cur] = min(low[cur], low[viz]); sub[cur] += sub[viz]; } } if(marcPA[cur]) comp[cur].push_back(make_pair(n - sub[cur], pai)); } void paint(int cur, int cor){ if(cnt == 0) return; ans[cur] = cor; cnt--; for(int i = 0; i < ar[cur].size(); i++){ int viz = ar[cur][i]; if(ans[viz] != 0) continue; paint(viz, cor); } }

Compilation message (stderr)

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  for(int i = 0; i < p.size(); i++){
      |                 ~~^~~~~~~~~~
split.cpp:61:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int i = 0; i < pa.size(); i++){
      |                 ~~^~~~~~~~~~~
split.cpp:38:6: warning: variable 'val3' set but not used [-Wunused-but-set-variable]
   38 |  int val3;
      |      ^~~~
split.cpp: In function 'void dfs(int, int)':
split.cpp:87:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |  for(int i = 0; i < ar[cur].size(); i++){
      |                 ~~^~~~~~~~~~~~~~~~
split.cpp: In function 'void paint(int, int)':
split.cpp:113:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |  for(int i = 0; i < ar[cur].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...