제출 #796120

#제출 시각아이디문제언어결과실행 시간메모리
796120_martynasSplit the Attractions (IOI19_split)C++14
40 / 100
63 ms17608 KiB
#include "split.h" #include <algorithm> #include <iostream> using namespace std; const int mxn = 1e5+5; bool visited[mxn]; int sz[mxn], par[mxn]; vector<int> color, adj[mxn]; vector<pair<int, int>> new_edges; void dfs(int u) { visited[u] = true; sz[u] = 1; for(int v : adj[u]) if(!visited[v]) { par[v] = u; new_edges.push_back({u, v}); dfs(v); sz[u] += sz[v]; } } int find_centroid(int u, int n) { visited[u] = true; for(int v : adj[u]) if(!visited[v] && 2*sz[v]>n) { return find_centroid(v, n); } return u; } void mark(int u, int m, int &cnt) { if(cnt <= 0) return; visited[u] = true; color[u] = m; cnt--; for(int v : adj[u]) if(!visited[v]) { mark(v, m, cnt); } } vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) { for(int i = 0; i < p.size(); i++) { int u = p[i], v = q[i]; adj[u].push_back(v), adj[v].push_back(u); } fill(par, par+n, -1); dfs(0); for(int i = 0; i < n; i++) { adj[i].clear(); } for(auto e : new_edges) { adj[e.first].push_back(e.second); adj[e.second].push_back(e.first); } fill(visited, visited+n, false); int centroid = find_centroid(0, n); fill(visited, visited+n, false); vector<pair<int, int>> groups = {pair<int, int>{a, 1}, pair<int, int>{b, 2}, pair<int, int>{c, 3}}; sort(groups.begin(), groups.end()); color.resize(n, groups[2].second); int small_group = -1; int cnt; if(par[centroid] != -1) sz[par[centroid]] = n-sz[centroid]; for(int u : adj[centroid]) { if(sz[u] >= groups[0].first) { visited[centroid] = true; cnt = groups[0].first; mark(u, groups[0].second, cnt); small_group = u; break; } } if(small_group == -1) return vector<int>(n, 0); fill(visited, visited+n, false); visited[small_group] = true; cnt = groups[1].first; mark(centroid, groups[1].second, cnt); return color; }

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

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:43:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     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...