Submission #305447

#TimeUsernameProblemLanguageResultExecution timeMemory
305447shahriarkhanNetwork (BOI15_net)C++14
0 / 100
11 ms12160 KiB
#include<bits/stdc++.h> using namespace std ; const int siz = 5e5 + 69 ; vector<int> adj[siz] ; int col[siz] ; void dfs(int s , int p) { for(int t : adj[s]) { if(t==p) continue ; dfs(t,s) ; col[t] = col[s] ; } } int main() { int n ; scanf("%d",&n) ; int deg[n+1] = {0} , mx = 0 , root = 0 ; for(int i = 1 ; i < n ; ++i) { int u , v ; scanf("%d%d",&u,&v) ; ++deg[u] , ++deg[v] ; mx = max(mx,max(deg[u],deg[v])) ; } for(int i = 1 ; i <= n ; ++i) { if(deg[i]==mx) { root = i ; break ; } } int cnt = 0 , cur = 1 ; for(int i : adj[root]) { col[i] = ++cnt ; dfs(i,root) ; } vector<pair<int,int> > ar ; for(int i = 1 ; i <= n ; ++i) { if(deg[i]==1) { ar.push_back({col[i],i}) ; } } int six = ar.size() ; sort(ar.begin(),ar.end()) ; if(six%2) { ar.push_back(ar[0]) ; ++six ; } printf("%d\n",(six+1)/2) ; for(int i = 0 ; i < six ; i += 2) { printf("%d %d\n",ar[i].second,ar[i+1].second) ; } return 0 ; }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:40:19: warning: unused variable 'cur' [-Wunused-variable]
   40 |     int cnt = 0 , cur = 1 ;
      |                   ^~~
net.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |     scanf("%d",&n) ;
      |     ~~~~~^~~~~~~~~
net.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |         scanf("%d%d",&u,&v) ;
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...