답안 #830219

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
830219 2023-08-19T00:03:25 Z yusuf12360 Network (BOI15_net) C++14
0 / 100
0 ms 212 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	vector<vector<int>> adj(n);
	vector<pair<int, int>> leaf, ans;
	map<int, int> mp;
	for(int i=1; i<n; i++) {
		int u, v; cin >> u >> v; --u; --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	} int cnt=0;
	for(int i=0; i<n; i++) {
		if(adj[i].size()>1) continue;
		leaf.push_back({adj[i][0], i});
		cnt++;
	}
	sort(leaf.begin(), leaf.end());
	for(int i=0; i<=cnt/2; i++) 
		ans.push_back({leaf[i].second, leaf[i+cnt/2].second});
	cout << ans.size() << '\n';
	for(auto p : ans) cout << p.first+1 << ' ' << p.second+1 << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Invalid number of links.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Invalid number of links.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Invalid number of links.
2 Halted 0 ms 0 KB -