QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#757724 | #9713. Kill the tree | propane# | WA | 67ms | 31252kb | C++20 | 1.2kb | 2024-11-17 12:47:11 | 2024-11-17 12:47:13 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
using LL = long long;
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n;
cin >> n;
vector<vector<int> > g(n + 1);
for(int i = 0; i < n - 1; i++){
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int> mx(n + 1), sz(n + 1), ans(n + 1), fa(n + 1);
auto dfs = [&](auto &&dfs, int u) -> void {
sz[u] = 1;
int heavy = 0;
for(auto j : g[u]){
if (j == fa[u]) continue;
fa[j] = u;
dfs(dfs, j);
sz[u] += sz[j];
if (sz[j] > sz[heavy]) heavy = j;
}
mx[u] = sz[heavy];
if (mx[u] * 2 <= sz[u]){
ans[u] = u;
}
else{
ans[u] = ans[heavy];
while(sz[u] - sz[ans[u]] * 2 > sz[u]) ans[u] = fa[ans[u]];
}
};
dfs(dfs, 1);
for(int i = 1; i <= n; i++){
cout << ans[i] << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 67ms
memory: 31252kb
input:
200000 42924 18271 60536 154257 107175 95680 196335 71607 158051 155259 110869 30974 143595 43516 4228 138046 26249 183847 123888 199873 15009 25362 166527 175160 15257 67159 124779 199363 148904 54047 5988 18123 58281 40739 44562 143880 72819 132492 137782 29662 130741 78276 55073 93292 82700 18328...
output:
1 46408 46408 46408 46408 167799 167799 167799 167799 167799 167799 46408 46408 46408 167799 167799 46408 46408 167799 46408 167799 46408 46408 167799 46408 167799 167799 46408 167799 167799 167799 167799 46408 46408 46408 46408 46408 167799 46408 46408 167799 46408 167799 167799 167799 46408 46408 ...
result:
wrong answer 2nd numbers differ - expected: '134385', found: '46408'