# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
320434 | 2020-11-08T18:41:11 Z | qpwoeirut | Easter Eggs (info1cup17_eastereggs) | C++17 | 2 ms | 620 KB |
#include <bits/stdc++.h> #include "grader.h" using namespace std; const int MN = 515; int N; int dist[MN], ct[MN], sum[MN]; set<int> adj[MN]; void dfs(int node, int par) { for (auto it=adj[node].begin(); it!=adj[node].end(); ++it) { if (*it == par) continue; dist[*it] = dist[node] + 1; dfs(*it, node); } ++ct[dist[node]]; } bool check(int mid) { int qdist = lower_bound(sum, sum+N, mid) - sum; vector<int> qnodes; for (int i=0; i<N; ++i) { if (dist[i] <= qdist) { qnodes.emplace_back(i+1); } } //cerr << "mid,qnodes: " << mid; for (int i=0; i<qnodes.size(); ++i) { cerr << ' ' << qnodes[i]; } cerr << endl; return query(qnodes); } vector<int> nodes, to_query; bool check2(int start, int finish) { int s = nodes.size(); assert(finish <= to_query.size()); nodes.insert(nodes.end(), to_query.begin() + start, to_query.begin() + finish); bool ret = query(nodes); nodes.resize(s); return ret; } int findEgg (int n, vector<pair<int,int>> bridges) { N = n; //cerr << "N: " << N << endl; for (int i=0; i<N; ++i) { dist[i] = ct[i] = sum[i] = 0; adj[i].clear(); query({1}); query({1}); query({1}); query({1}); query({1}); } nodes.clear(); to_query.clear(); for (int i=0; i<bridges.size(); ++i) { int u = bridges[i].first, v = bridges[i].second; --u; --v; adj[u].emplace(v); adj[v].emplace(u); } dist[0] = 0; dfs(0, -1); sum[0] = ct[0]; for (int i=1; i<N; ++i) { sum[i] = sum[i-1] + ct[i]; } int lo = 1, hi = N+1; while (lo < hi) { int mid = (lo + hi) >> 1; if (!check(mid)) { lo = mid + 1; } else { hi = mid; } } int egg_depth = lower_bound(sum, sum+N, lo) - sum; //cerr << "depth: " << egg_depth << endl; for (int i=0; i<N; ++i) { //cerr << "i: " << i << endl; if (dist[i] < egg_depth) nodes.emplace_back(i+1); if (dist[i] == egg_depth) to_query.emplace_back(i+1); } lo = 0, hi = to_query.size(); while (lo < hi) { int mid = (lo + hi) >> 1; //cerr << "mid: " << mid << endl; if (!check2(lo, mid+1)) { lo = mid + 1; } else { hi = mid; } } //cerr << "lo: " << lo << endl; assert(lo < to_query.size()); return to_query[lo]; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 492 KB | Execution killed with signal 6 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 620 KB | Execution killed with signal 6 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 620 KB | Execution killed with signal 6 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |