QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#695832#5502. Dazzling MountainOOBMABTRAMS#WA 790ms71440kbC++17911b2024-10-31 20:53:222024-10-31 20:53:27

Judging History

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

  • [2024-10-31 20:53:27]
  • 评测
  • 测评结果:WA
  • 用时:790ms
  • 内存:71440kb
  • [2024-10-31 20:53:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=1e9+7;
const int N=1000013;
vector<int>mp[N];
basic_string<int>s[N];

int v[N],sz[N];
void dfs(int x,int fa) {
    sz[x]=1;
    basic_string<int>v;
    for(auto i:mp[x])if(i^fa)dfs(i,x),sz[x]+=sz[i],v+=s[i];
    if(mp[x].size()>1+(x!=1)) {
        sort(v.begin(),v.end());
        for(int i=1,f=0;i<v.size();i++)if(!f&&v[i]==v[i-1])f=1,s[x]+=v[i];else if(v[i]!=v[i-1])f=0;
    }else swap(s[x],v);
    s[x]+=sz[x];
}

void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)mp[i].clear(),v[i]=0,s[i].clear();
    for(int i=1,x,y;i<n;i++)cin>>x>>y,mp[x].push_back(y),mp[y].push_back(x);
    dfs(1,0);
    vector<int>b;
    cout<<s[1].size()<<'\n';
    for(auto x:s[1])cout<<x<<' ';cout<<'\n';
}

int main(){
    ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 60584kb

input:

1
9
1 2
2 3
3 4
3 5
2 6
6 7
7 8
7 9

output:

4
1 3 8 9 

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 790ms
memory: 71440kb

input:

10000
906
675 189
555 889
491 97
791 419
175 694
713 842
788 513
159 354
670 815
652 546
253 87
89 278
563 429
522 900
202 657
331 865
35 605
735 532
612 471
657 386
7 886
856 164
224 777
73 534
481 631
711 698
240 465
115 181
191 825
311 155
709 501
207 849
294 546
591 682
96 405
210 696
861 13
781...

output:

68
1 2 3 4 5 6 7 8 34 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 
6
1 2 3 4 5 11 
28
1 2 3 4 5 6 15 16 17 1...

result:

wrong answer 1st lines differ - expected: '63', found: '68'