QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#284391#7936. Eliminate Treeucup-team896#WA 69ms19456kbC++141010b2023-12-16 13:23:272023-12-16 13:23:28

Judging History

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

  • [2023-12-16 13:23:28]
  • 评测
  • 测评结果:WA
  • 用时:69ms
  • 内存:19456kb
  • [2023-12-16 13:23:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7;
int n,du[N],ok[N];
vector<int>e[N];
set<int>s;
void del(int id){
    for(auto v:e[id]){
        du[v]--;
        if(!ok[v]&&du[v]<=1)s.insert(v);
    }
    return;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cin>>n;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        e[u].push_back(v);
        e[v].push_back(u);
        du[u]++;
        du[v]++;
    }
    for(int i=1;i<=n;i++){
        if(du[i]==1)s.insert(i);
    }
    int ans=0;
    while(!s.empty()){
        int u=(*s.begin());
        s.erase(s.begin());
        if(ok[u])continue;
        ok[u]=1;ans++;
        int fl=1;
        for(auto x:e[u])if(!ok[x]){
            if(du[x]<=2){
                ok[x]=1;
                del(u);
                del(x);
            }else{
                del(u);
                ans++;
            }fl=0;
        }ans+=fl;
    }
    cout<<ans<<"\n";
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 9476kb

input:

5
1 2
2 3
3 4
3 5

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 1ms
memory: 8272kb

input:

4
1 2
2 3
3 4

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 69ms
memory: 19456kb

input:

196666
32025 108673
181779 17115
162570 134230
93003 39673
89144 1269
185919 154408
34896 65369
35860 44720
55698 1390
45520 189805
147867 124511
135459 132555
87303 18031
176314 59695
33352 130640
87272 39716
35749 108807
143493 94486
126512 116598
40212 70895
132216 80855
22241 188737
150354 17346...

output:

169523

result:

wrong answer 1st numbers differ - expected: '138182', found: '169523'