# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1067866 |
2024-08-21T04:52:42 Z |
Plurm |
Torrent (COI16_torrent) |
C++11 |
|
2000 ms |
40892 KB |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[300005];
int dep[300005];
vector<int> par[300005];
int chcnt[300005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, a, b;
cin >> n >> a >> b;
for (int i = 1; i < n; i++) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
memset(dep, 0x3f, sizeof(dep));
dep[a] = dep[b] = 0;
queue<int> q;
q.push(a);
q.push(b);
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v : g[u]) {
if (dep[v] > dep[u] + 1) {
dep[v] = dep[u] + 1;
par[v] = {u};
q.push(v);
} else if (dep[v] == dep[u] + 1) {
par[v].push_back(u);
}
}
}
priority_queue<pair<int, int>> pq;
for (int i = 1; i <= n; i++) {
for (int p : par[i])
chcnt[p]++;
}
for (int i = 1; i <= n; i++) {
if (chcnt[i] == 0 && i != a && i != b)
pq.push({dep[i], i});
}
int rnd = 0;
while (!pq.empty()) {
rnd++;
vector<int> waitlist;
set<int> parf;
while (!pq.empty()) {
auto p = pq.top();
pq.pop();
int chosen = -1;
for (int pr : par[p.second]) {
if (!parf.count(pr)) {
chosen = pr;
}
}
if (chosen == -1) {
waitlist.push_back(p.second);
} else {
parf.insert(chosen);
for (int pr : par[p.second]) {
chcnt[pr]--;
}
}
}
for (int u : parf) {
if (chcnt[u] == 0 && u != 0 && u != a && u != b)
pq.push({dep[u], u});
}
for (int u : waitlist)
pq.push({dep[u], u});
}
cout << rnd << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
16732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2033 ms |
40892 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |