Submission #655934

#TimeUsernameProblemLanguageResultExecution timeMemory
655934aebovNetwork (BOI15_net)C++17
0 / 100
7 ms12004 KiB
#include<iostream>
#include<vector>
#include<cstring>
#include<utility>
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
using namespace std;

const int N = (int)5e5 + 5;
int n , u, v, d[N];
vector<int> leafs;
vector<pii> ret;
vector<int> adj[N]; 

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1; i < n ; i ++){
		cin >> u >> v;
		d[u] ++, d[v] ++;
	}
	for(int i = 1; i <= n; i ++)if(d[i] == 1)leafs.pb(i);
	if(leafs.size() & 1){
		if(leafs[0] == 1)ret.pb({1, n});
		else ret.pb({leafs[0], 1});
		for(int i = 1; i < leafs.size();i += 2)ret.pb({leafs[i], leafs[i+1]});
	}
	else{
		for(int i = 0; i < leafs.size(); i += 2)ret.pb({leafs[i], leafs[i+1]});
	}
	cout << ret.size() << endl;
	for(auto [x, y] : ret)cout << x << " " << y << endl;
}

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   for(int i = 1; i < leafs.size();i += 2)ret.pb({leafs[i], leafs[i+1]});
      |                  ~~^~~~~~~~~~~~~~
net.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int i = 0; i < leafs.size(); i += 2)ret.pb({leafs[i], leafs[i+1]});
      |                  ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...