Submission #83443

#TimeUsernameProblemLanguageResultExecution timeMemory
83443nikolapesic2802Network (BOI15_net)C++14
100 / 100
668 ms153300 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define pb push_back using namespace std; using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; ///find_by_order(),order_of_key() const int N=500005; vector<vector<int> > graf(N); vector<int> leaves; void dfs(int tr,int par) { if(graf[tr].size()==1) leaves.pb(tr); for(auto p:graf[tr]) { if(p==par) continue; dfs(p,tr); } } int main() { int n; scanf("%i",&n); for(int i=1;i<n;i++) { int a,b; scanf("%i %i",&a,&b); graf[a].pb(b); graf[b].pb(a); } dfs(1,-1); int t=leaves.size()/2; printf("%i\n",(leaves.size()+1)/2); for(int i=0;i<(leaves.size()+1)/2;i++) { printf("%i %i\n",leaves[i],leaves[i+t]); } return 0; }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:41:38: warning: format '%i' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     printf("%i\n",(leaves.size()+1)/2);
                   ~~~~~~~~~~~~~~~~~~~^
net.cpp:42:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<(leaves.size()+1)/2;i++)
                 ~^~~~~~~~~~~~~~~~~~~~
net.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&n);
     ~~~~~^~~~~~~~~
net.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i %i",&a,&b);
         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...