QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#178170 | #5502. Dazzling Mountain | real_sigma_team# | WA | 0ms | 31400kb | C++20 | 1.2kb | 2023-09-13 18:56:19 | 2023-09-13 18:56:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using ll = long long;
const int N = 1e6 + 5;
vector<int> gr[N];
int d[N], d1[N], d2[N];
void dfs(int v, int p) {
int c = 0;
d[v] = 1;
for (int u: gr[v]) {
if (u == p)
continue;
dfs(u, v);
d[v] += d[u];
d1[v] += d1[u];
c++;
}
if (c == 0)
d1[v] = 1;
d2[d[v]] += d1[v];
}
void solve() {
int n;
cin >> n;
for (int i = 0; i <= n; i++) {
gr[i].clear();
d2[i] = d1[i] = d[i] = 0;
}
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
u--, v--;
gr[v].push_back(u);
gr[u].push_back(v);
}
dfs(0, -1);
for (int i = 0; i <= n; i++) {
if (d2[i] == d1[0]) {
cout << i << ' ';
}
}
cout << '\n';
}
int main() {
#ifndef LOCAL
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#else
freopen("input.txt", "r", stdin);
#endif
int t;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 31400kb
input:
1 9 1 2 2 3 3 4 3 5 2 6 6 7 7 8 7 9
output:
1 3 8 9
result:
wrong answer 1st lines differ - expected: '4', found: '1 3 8 9 '