제출 #126208

#제출 시각아이디문제언어결과실행 시간메모리
126208VardanyanNetwork (BOI15_net)C++14
0 / 100
15 ms12152 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 500*1000+5;
vector<int> g[N];
int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i = 1;i<=n-1;i++){
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    vector<int> lf;
    for(int i = 1;i<=n;i++){
        if(g[i].size() == 1) lf.push_back(i);
    }
    random_shuffle(lf.begin(),lf.end());
    cout<<(lf.size()+1)/2<<endl;
    for(int i = 0;i<lf.size()-1;i+=2){
        cout<<lf[i]<< " "<<lf[i+1]<<endl;
    }
    if(lf.size()%2){
        cout<<lf[lf.size()-1]<<" "<<lf[0]<<endl;
    }
    return 0;
}

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

net.cpp: In function 'int main()':
net.cpp:21:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<lf.size()-1;i+=2){
                   ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...