Submission #209546

#TimeUsernameProblemLanguageResultExecution timeMemory
209546DodgeBallManNetwork (BOI15_net)C++14
100 / 100
580 ms47732 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; int n; vector<int> g[N], lf; void dfs( int u, int p ) { if( g[u].size() == 1 ) lf.emplace_back( u ); for( int v : g[u] ) if( v != p ) dfs( v, u ); } int main() { scanf("%d",&n); for( int i = 1, a, b ; i < n ; i++ ) { scanf("%d %d",&a,&b); g[a].emplace_back( b ), g[b].emplace_back( a ); } dfs( 1, 0 ); printf("%d\n",lf.size()/2 + ( lf.size() % 2 ) ); for( int i = 0 ; i < lf.size()/2 ; i++ ) printf("%d %d\n",lf[i],lf[i+(lf.size()/2)]); if( lf.size() % 2 ) printf("%d %d\n",lf[0],lf[lf.size()-1]); return 0; }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:19:51: 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",lf.size()/2 + ( lf.size() % 2 ) );
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
net.cpp:20:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for( int i = 0 ; i < lf.size()/2 ; i++ ) printf("%d %d\n",lf[i],lf[i+(lf.size()/2)]);
                      ~~^~~~~~~~~~~~~
net.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
net.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...