제출 #614169

#제출 시각아이디문제언어결과실행 시간메모리
614169AlperenTSplit the Attractions (IOI19_split)C++17
0 / 100
6 ms9812 KiB
#include <bits/stdc++.h> #include "split.h" using namespace std; const int N = 2e5 + 5; vector<int> graph[N]; vector<int> ans; int n, a, b, c; void fill_ans(int v, int bad, int cnt, int typ){ vector<bool> vis(n, false); int curcnt = 1; queue<int> que; que.push(v), vis[v] = true; while(curcnt < cnt){ int v = que.front(); que.pop(); for(auto e : graph[v]){ if(!vis[e] && e != bad){ vis[e] = true; que.push(e); curcnt++; if(curcnt == cnt) break; } } } for(int i = 0; i < n; i++) if(vis[i]) ans[i] = typ; } bool flag = false; int dfs(int v, int p){ if(flag) return 0; int cnt = 1; for(auto e : graph[v]){ if(e != p) cnt += dfs(e, v); } if(cnt >= a){ if(n - cnt >= b){ fill_ans(v, p, a, 1); fill_ans(p, v, b, 2); flag = true; return 0; } else if(n - cnt >= c){ fill_ans(v, p, a, 1); fill_ans(p, v, c, 3); flag = true; return 0; } } if(cnt >= b){ if(n - cnt >= a){ fill_ans(v, p, b, 2); fill_ans(p, v, a, 1); flag = true; return 0; } else if(n - cnt >= c){ fill_ans(v, p, b, 2); fill_ans(p, v, c, 3); flag = true; return 0; } } if(cnt >= c){ if(n - cnt >= a){ fill_ans(v, p, c, 3); fill_ans(p, v, a, 1); flag = true; return 0; } else if(n - cnt >= b){ fill_ans(v, p, c, 3); fill_ans(p, v, b, 2); flag = true; return 0; } } return cnt; } vector<int> find_split(int n_, int a_, int b_, int c_, vector<int> p, vector<int> q){ int n = n_, a = a_, b = b_, c = c_, m = p.size(); ans.assign(n, 0); for(int i = 0; i < m; i++){ graph[p[i]].push_back(q[i]); graph[q[i]].push_back(p[i]); } if(a == 1){ // Subtask 2 fill_ans(0, -1, b, 2); for(int i = 0; i < n; i++){ if(ans[i] == 0){ ans[i] = 1; break; } } for(int i = 0; i < n; i++){ if(ans[i] == 0){ ans[i] = 3; } } } else if(m == n - 1){ // Subtask 1 & 3 dfs(1, 0); } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:107:30: warning: unused variable 'c' [-Wunused-variable]
  107 |  int n = n_, a = a_, b = b_, c = c_, m = p.size();
      |                              ^
#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...