QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#225157#5502. Dazzling MountainGawor270WA 0ms3648kbC++141.7kb2023-10-24 01:46:592023-10-24 01:47:00

Judging History

你现在查看的是最新测评结果

  • [2023-10-24 01:47:00]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3648kb
  • [2023-10-24 01:46:59]
  • 提交

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'