Submission #317861

#TimeUsernameProblemLanguageResultExecution timeMemory
317861Kesatria_KomodoNetwork (BOI15_net)C++17
0 / 100
8 ms12032 KiB
#include <cstdio> #include <vector> std::vector<int> leaf , adjlist[500001]; void dfs(int node , int par){ for (int it : adjlist[node]) if (it != par) dfs(it , node); if (adjlist[node].size() == 1) leaf.push_back(node); } int main(){ int n; scanf("%d" , &n); for (int i = 1 ; i < n ; i++){ int a , b; scanf("%d%d" , &a , &b); adjlist[a].push_back(b); adjlist[b].push_back(a); } for (int i = 1 ; i <= n ; i++) if (adjlist[i].size() > 1){ dfs(i , i); break; } printf("%u\n" , leaf.size() / 2 + leaf.size() % 2); for (int i = 1 ; i < leaf.size() ; i += 2) printf("%d %d\n" , leaf[i] , leaf[i - 1]); if (leaf.size() & 1) printf("%d %d\n" , leaf[leaf.size() - 1] , leaf[leaf.size() - 2]); }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:25:14: warning: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   25 |     printf("%u\n" , leaf.size() / 2 + leaf.size() % 2);
      |             ~^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |              |                      |
      |              unsigned int           std::vector<int>::size_type {aka long unsigned int}
      |             %lu
net.cpp:26:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int i = 1 ; i < leaf.size() ; i += 2)
      |                      ~~^~~~~~~~~~~~~
net.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |     scanf("%d" , &n);
      |     ~~~~~^~~~~~~~~~~
net.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |         scanf("%d%d" , &a , &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...