제출 #406279

#제출 시각아이디문제언어결과실행 시간메모리
406279victoriadNetwork (BOI15_net)C++14
0 / 100
1 ms204 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;
bool v=false;
for(int i=0;i<n;i++){
  if(padre[i].first>2){
  for(int k=0;k<padre[i].second.size();k++){
    if(x-u<2){
    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;
    }
  }
  else{
    if(k<padre[i].second.size()-2){
      if(k%2==0){
        cout<<padre[i].second[k]+1<<" ";
        v=true;
      }
      else 
      {cout<<padre[i].second[k]+1<<"\n";
      v=false;
      u++;
      }
      nodo[padre[i].second[k]].first=-1;
    }
    if(v && k==padre[i].second.size()-2){
       cout<<padre[i].second[k]+1<<"\n";
      v=false;
      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;
}

컴파일 시 표준 에러 (stderr) 메시지

net.cpp: In function 'int main()':
net.cpp:55:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for(int k=0;k<padre[i].second.size();k++){
      |               ~^~~~~~~~~~~~~~~~~~~~~~~
net.cpp:57:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     if(k<padre[i].second.size()-1){
      |        ~^~~~~~~~~~~~~~~~~~~~~~~~~
net.cpp:67:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     if(k==padre[i].second.size()-1 && k%2==1){
      |        ~^~~~~~~~~~~~~~~~~~~~~~~~~~
net.cpp:74:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     if(k<padre[i].second.size()-2){
      |        ~^~~~~~~~~~~~~~~~~~~~~~~~~
net.cpp:86:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     if(v && k==padre[i].second.size()-2){
      |             ~^~~~~~~~~~~~~~~~~~~~~~~~~~
net.cpp:109:26: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
  109 |     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...