UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212689#3829. Ceam25390735ms56240kbC++11799b2024-10-20 09:41:502024-10-20 12:37:39

answer

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    if(n == 1){
        cout << "0\n";
        return 0;
    }
    vector<vector<int>> adj(n+1, vector<int>());
    for(int i=0; i<n-1; ++i){
        int x, y;
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int leaf_count =0;
    for(int i=1; i<=n; ++i){
        if(i ==1){
            if(adj[i].size() ==0){
            }
            continue;
        }
        if(adj[i].size() ==1){
            leaf_count++;
        }
    }
    long long minimal_sum = (long long)(n-1) + (leaf_count /2);
    
    cout << minimal_sum;
}

详细

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

5
3 1
1 5
2 4
5 4

output:

5

result:

wrong answer 1st numbers differ - expected: '4', found: '5'

Subtask #2:

score: 0
Wrong Answer

Test #4:

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

input:

100
63 38
17 33
44 12
9 66
21 98
2 49
68 67
75 42
78 25
92 6
67 17
90 19
48 51
83 9
20 94
68 4
64 58...

output:

120

result:

wrong answer 1st numbers differ - expected: '167', found: '120'

Subtask #3:

score: 0
Wrong Answer

Test #10:

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

input:

1000
228 978
939 994
911 13
8 806
680 958
779 832
673 924
627 806
354 476
320 218
766 848
171 944
90...

output:

1192

result:

wrong answer 1st numbers differ - expected: '1893', found: '1192'

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 34ms
memory: 6604kb

input:

100000
44881 88880
79640 18741
56510 31493
27649 50461
7015 98523
26337 91384
17594 52397
37312 3409...

output:

118419

result:

wrong answer 1st numbers differ - expected: '199052', found: '118419'

Subtask #5:

score: 0
Wrong Answer

Test #22:

score: 0
Wrong Answer
time: 701ms
memory: 56240kb

input:

1000000
198444 939986
569807 470692
847908 557044
739959 80274
772656 222835
832266 382872
267873 10...

output:

1184275

result:

wrong answer 1st numbers differ - expected: '1994506', found: '1184275'