Submission #406264

#TimeUsernameProblemLanguageResultExecution timeMemory
406264victoriadNetwork (BOI15_net)C++14
0 / 100
1 ms312 KiB
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <utility> #include <queue> #include <map> #include <iomanip> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); int n,a,b; cin>>n; vector<vector<int> >g(n); for(int i=0;i<n-1;i++){ cin>>a>>b; a--; b--; g[a].push_back(b); g[b].push_back(a); } vector<int>j; int con=0; vector<pair<int,vector<int> > >padre(n,make_pair(0,j)); vector<pair<int,int> >nodo(n,make_pair(-1,-1)); for(int i=0;i<n;i++){ if(g[i].size()==1){ int p=g[i][0]; nodo[i]=make_pair(i,p); j=padre[p].second; j.push_back(i); padre[p].second=j; padre[p].first++; con++; } } int x=con; if(x%2==0){ cout<<x/2<<"\n"; x/=2; } else{ cout<<x/2+1<<"\n"; x/=2; x++; } int u=0; for(int i=0;i<n;i++){ if(padre[i].first>2){ for(int k=0;k<padre[i].second.size();k++){ if(k<padre[i].second.size()-1){ if(k%2==0){ cout<<padre[i].second[k]+1<<" "; } else {cout<<padre[i].second[k]+1<<"\n"; u++; } nodo[padre[i].second[k]].first=-1; } if(k==padre[i].second.size()-1 && k%2==1){ cout<<padre[i].second[k]+1<<"\n"; u++; nodo[padre[i].second[k]].first=-1; } } } } int p,k=0; while(u<x){ bool im=false; for(int i=k;i<n;i++){ if(nodo[i].first!=-1){ cout<<nodo[i].first+1<<" "; nodo[i].first=-1; p=nodo[i].second; k=i; break; } } for(int i=k;i<n;i++){ if(nodo[i].first!=-1 &&nodo[i].second!=p){ cout<<nodo[i].first+1<<"\n"; nodo[i].first=-1; im=true; break; } } if(!im){ for(int i=0;i<n;i++){ if(i!=p && i!=k){ cout<<i+1<<"\n"; break; } } } u++; } return 0; }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:54:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int k=0;k<padre[i].second.size();k++){
      |               ~^~~~~~~~~~~~~~~~~~~~~~~
net.cpp:55:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     if(k<padre[i].second.size()-1){
      |        ~^~~~~~~~~~~~~~~~~~~~~~~~~
net.cpp:65:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     if(k==padre[i].second.size()-1 && k%2==1){
      |        ~^~~~~~~~~~~~~~~~~~~~~~~~~~
net.cpp:86:26: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   86 |     if(nodo[i].first!=-1 &&nodo[i].second!=p){
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...