QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#185908#5502. Dazzling MountainmartaWA 0ms3524kbC++141.1kb2023-09-22 19:45:312023-09-22 19:45:31

Judging History

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

  • [2023-09-22 19:45:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3524kb
  • [2023-09-22 19:45:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int t;
vector<vector<int>> v;
vector<int> sajz;
vector<bool>vis;

void dfs(int x)
{
    sajz[x]=1;
    vis[x]=1;
    for(auto u:v[x]) if(!vis[u]) {dfs(u); sajz[x]+=sajz[u];}

}

void solve()
{
    set<int> pq;
    int n;
    cin>>n;
    map <int, int> mapa, ilerazy;
    v.clear();
    v.resize(n+5);
    vis.clear();
    vis.resize(n+5);
    sajz.clear();
    sajz.resize(n+1);
    for(int i=0; i<n-1; i++)
    {
        int a, b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    dfs(1);
    //for(auto u:sajz) cout<<u<<" ";
    //cout<<'\n';
    sort(sajz.begin(), sajz.end());

    for(int i=1; i<=n; i++)
    {
        if(mapa.find(sajz[i])==mapa.end()) mapa[sajz[i]]=i-1;
        ilerazy[sajz[i]]++;

        if((sajz[i]-1)*ilerazy[sajz[i]]==mapa[sajz[i]]) pq.insert(sajz[i]);
        //cout<<"mapa["<<sajz[i]<<"]="<<mapa[sajz[i]]<<"  "<<ilerazy[sajz[i]]<<"\n";
    }
    for(auto u:pq) cout<<u<<" ";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>t;
    while(t--) solve();
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3524kb

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 '