제출 #984307

#제출 시각아이디문제언어결과실행 시간메모리
984307michifiedSplit the Attractions (IOI19_split)C++17
40 / 100
124 ms46160 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; struct node_t { int ord, low, ss, par; vector<int> adj; unordered_set<int> used; }; vector<node_t> nodes; vector<int> thing, ord2id, ans; int lo, t = 0, n, remain; bool good = true; pair<int, int> found = {-1, -1}; void dfs(int cur, int par) { if (not good) return; node_t& u = nodes[cur]; u.par = par; int mcss = 0; t++; u.ord = u.low = t; u.ss = 1; ord2id[t] = cur; for (int v : u.adj) { if (not nodes[v].ord) { dfs(v, cur); u.low = min(u.low, nodes[v].low); u.used.insert(v); nodes[v].used.insert(cur); u.ss += nodes[v].ss; mcss = max(mcss, nodes[v].ss); } else if (v != par) { u.low = min(u.low, nodes[v].ord); } } if (found.first != -1) return; if (mcss < lo and u.ss >= lo) { if (par == -1) { good = false; return; } if (u.ss <= n - lo) { u.used.erase(par); nodes[par].used.erase(cur); found = make_pair(cur, par); return; } int curss = u.ss; for (int v : u.adj) { if (v == par) continue; if (nodes[v].low < u.low) { curss -= nodes[v].ss; u.used.erase(v); nodes[v].used.erase(cur); nodes[ord2id[nodes[v].low]].used.insert(v); nodes[v].used.insert(ord2id[nodes[v].low]); if (curss <= n - lo) { found = make_pair(cur, par); return; } } } } } bool construct(int cur, int group, int par) { if (remain == 0) return true; ans[cur] = group; remain--; bool res = false; for (int v : nodes[cur].used) { if (v == par) continue; res = res or construct(v, group, cur); } return res; } vector<int> find_split(int N, int a, int b, int c, vector<int> p, vector<int> q) { int i; n = N; nodes.resize(n); ord2id.resize(n + 1); lo = min(min(a, b), c); vector<pair<int, int>> thing = {{a, 1}, {b, 2}, {c, 3}}; sort(thing.begin(), thing.end()); for (i = 0; i < q.size(); i++) { nodes[p[i]].adj.push_back(q[i]); nodes[q[i]].adj.push_back(p[i]); } dfs(0, -1); ans.resize(n); if (not good or found.first == -1) return ans; remain = thing[1].first; bool ok = construct(found.first, thing[1].second, found.second); if (not ok) { remain = thing[1].first; construct(found.first, 0, found.second); remain = thing[0].first; construct(found.first, thing[0].second, found.second); remain = thing[1].first; construct(found.second, thing[1].second, found.first); } else { remain = thing[0].first; construct(found.second, thing[0].second, found.first); } for (i = 0; i < n; i++) { if (ans[i] == 0) ans[i] = thing[2].second; } return ans; }

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

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