Submission #19558869


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> graph;
int DFS(int v, int parent_v = -1){
    int antenna = 0, none = 0;
    for(int child_v : graph[v]){
        if(child_v == parent_v) continue;

        int sub = DFS(child_v, v);
        if(sub == 0) none += 1;
        if(sub != 0) antenna += sub;
    }
    if(none != 0) antenna += none - 1;// to distinguish (none) child_v's, we need (none - 1) antennas on child_v's
    return antenna;
}

int main(){
    int n;
    cin >> n;

    graph.resize(n);
    for(int i=0; i<n-1; i++){
        int a, b;
        cin >> a >> b;

        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    for(int i=0; i<n; i++){
        if((int)graph[i].size() >= 3){
            cout << DFS(i) << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}

Submission Info

Submission Time
Task E - Antennas on Tree
User probably
Language C++ (GCC 9.2.1)
Score 900
Code Size 881 Byte
Status AC
Exec Time 80 ms
Memory 11860 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 3
AC × 26
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt
Case Name Status Exec Time Memory
0_00.txt AC 9 ms 3448 KB
0_01.txt AC 3 ms 3448 KB
0_02.txt AC 3 ms 3452 KB
1_00.txt AC 2 ms 3596 KB
1_01.txt AC 2 ms 3416 KB
1_02.txt AC 3 ms 3588 KB
1_03.txt AC 2 ms 3564 KB
1_04.txt AC 2 ms 3412 KB
1_05.txt AC 4 ms 3576 KB
1_06.txt AC 80 ms 8712 KB
1_07.txt AC 67 ms 8912 KB
1_08.txt AC 73 ms 8688 KB
1_09.txt AC 67 ms 9032 KB
1_10.txt AC 72 ms 11860 KB
1_11.txt AC 74 ms 10332 KB
1_12.txt AC 73 ms 8708 KB
1_13.txt AC 72 ms 8716 KB
1_14.txt AC 73 ms 8748 KB
1_15.txt AC 72 ms 8720 KB
1_16.txt AC 77 ms 8576 KB
1_17.txt AC 74 ms 8748 KB
1_18.txt AC 66 ms 9000 KB
1_19.txt AC 69 ms 8920 KB
1_20.txt AC 68 ms 8888 KB
1_21.txt AC 67 ms 9112 KB
1_22.txt AC 69 ms 8960 KB