Submission #44631

#TimeUsernameProblemLanguageResultExecution timeMemory
44631RayaBurong25_1Network (BOI15_net)C++17
0 / 100
14 ms12132 KiB
#include <stdio.h> #include <vector> std::vector<int> AdjList[500005]; std::vector<int> Leaf; int Root; void dfs(int u, int pa) { if (pa == 0) Root = u; int i, v, s = AdjList[u].size(); for (i = 0; i < s; i++) { v = AdjList[u][i]; if (v != pa) { dfs(v, u); } } if (s == 1) Leaf.push_back(u); } int main() { int N; scanf("%d", &N); int i, j, u, v; for (i = 0; i < N - 1; i++) { scanf("%d %d", &u, &v); AdjList[u].push_back(v); AdjList[v].push_back(u); } if (AdjList[1].size() > 1) dfs(1, 0); else dfs(AdjList[1][0], 0); printf("%d\n", (Leaf.size() + 1)/2); for (i = 0, j = Leaf.size() - 1; i < j; i++, j--) printf("%d %d\n", Leaf[i], Leaf[j]); if (i == j) printf("%d %d\n", Leaf[i], Root); }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:37:39: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n", (Leaf.size() + 1)/2);
                    ~~~~~~~~~~~~~~~~~~~^
net.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
net.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...