Submission #5646954
Source Code Expand
#include <cstdio> #include <vector> std::vector<int> adj[100005]; int dfs(int u, int fa = -1) { int ans = 0, zero = 0; for (int v : adj[u]) { if (v == fa) continue; int res = dfs(v, u); ans += res; zero += !res; } return ans + (zero ? zero - 1 : 0); } int main() { // freopen("F.in", "r", stdin); int n; scanf("%d", &n); for (int i = 1; i < n; i++) { int u, v; scanf("%d%d", &u, &v); adj[u].push_back(v); adj[v].push_back(u); } int rt = -1; for (int i = 0; i < n && rt == -1; i++) { if (adj[i].size() >= 3) rt = i; } if (-1 == rt) puts("1"); else printf("%d\n", dfs(rt)); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Antennas on Tree |
User | diamond_duke |
Language | C++14 (GCC 5.4.1) |
Score | 900 |
Code Size | 670 Byte |
Status | AC |
Exec Time | 52 ms |
Memory | 9088 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:21:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:25:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &u, &v); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 900 / 900 | ||||
Status |
|
|
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 | 2 ms | 2560 KB |
0_01.txt | AC | 2 ms | 2560 KB |
0_02.txt | AC | 2 ms | 2560 KB |
1_00.txt | AC | 2 ms | 2560 KB |
1_01.txt | AC | 2 ms | 2560 KB |
1_02.txt | AC | 2 ms | 2560 KB |
1_03.txt | AC | 2 ms | 2560 KB |
1_04.txt | AC | 2 ms | 2560 KB |
1_05.txt | AC | 2 ms | 2560 KB |
1_06.txt | AC | 37 ms | 5760 KB |
1_07.txt | AC | 29 ms | 6136 KB |
1_08.txt | AC | 37 ms | 5760 KB |
1_09.txt | AC | 30 ms | 6136 KB |
1_10.txt | AC | 47 ms | 9088 KB |
1_11.txt | AC | 47 ms | 7296 KB |
1_12.txt | AC | 47 ms | 5888 KB |
1_13.txt | AC | 52 ms | 5760 KB |
1_14.txt | AC | 39 ms | 5760 KB |
1_15.txt | AC | 38 ms | 5760 KB |
1_16.txt | AC | 39 ms | 5760 KB |
1_17.txt | AC | 40 ms | 5888 KB |
1_18.txt | AC | 35 ms | 6016 KB |
1_19.txt | AC | 34 ms | 6272 KB |
1_20.txt | AC | 35 ms | 6144 KB |
1_21.txt | AC | 33 ms | 6144 KB |
1_22.txt | AC | 31 ms | 6136 KB |