QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#225157 | #5502. Dazzling Mountain | Gawor270 | WA | 0ms | 3648kb | C++14 | 1.7kb | 2023-10-24 01:46:59 | 2023-10-24 01:47:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << "[" << #x << " " << x << "] ";
#define ar array
#define ll long long
#define ld long double
#define sz(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
typedef pair<int,int> pi;
const int MAX_N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;
vector<vector<int>> tree;
vector<int> dh;
vector<bool> vis;
pi countleafes(int v){
vis[v] = true;
int count = 0;
int countl = 0;
int sum = 0;
for(int u : tree[v]){
if(!vis[u]){
count++;
pi res = countleafes(u);
sum += res.first;
countl += res.second;
}
}
if(count){
dh[sum] += countl;
return {sum+1,countl};
}
else{
return {1,1};
}
}
void solve() {
int n;
cin >> n;
tree.resize(n);
dh.resize(n);
vis.resize(n,false);
for(int i=0; i<n-1; i++){
int a,b;
cin >> a >> b;
tree[--a].push_back(--b);
tree[b].push_back(a);
}
int no_leafes = countleafes(0).second;
int count = 0;
vi ans = {1};
for(int i=0; i<n; i++){
if(dh[i] == no_leafes){
count++;
ans.push_back(i+1);
}
}
cout << count << "\n";
for(int x : ans){
cout << x << " ";
}
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int tc = 1;
cin >> tc;
for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3648kb
input:
1 9 1 2 2 3 3 4 3 5 2 6 6 7 7 8 7 9
output:
3 1 3 8 9
result:
wrong answer 1st lines differ - expected: '4', found: '3'