답안 #735654

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
735654 2023-05-04T12:35:17 Z MODDI Network (BOI15_net) C++14
0 / 100
7 ms 12500 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
int n;
vi G[500100], leaf;
bool vis[500100];
void dfs(int at, int p){
	bool made=  false;
	vis[at] = true;
	for(auto next : G[at]){
		if(!vis[next]){
			made = true;
			dfs(next, at);
		}
	}
	if(!made){
		leaf.pb(at);
	}
}
int main(){
	cin>>n;
	for(int i = 1; i < n; i++){
		int a, b;
		cin>>a>>b;
		a--; b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	memset(vis, false, sizeof vis);
	dfs(0, -1);
//	vis[0] = true;
	vector<pii> ans;
	for(int i = 0; i < leaf.size()-1; i+=2){
		ans.pb(mp(leaf[i]+1, leaf[i+1]+1));
	}
	ans.pb(mp(leaf[leaf.size()-1], 1));
	cout<<ans.size()<<endl;
	for(auto t : ans)
		cout<<t.first<<" "<<t.second<<endl;
	return 0;
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i = 0; i < leaf.size()-1; i+=2){
      |                 ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 12500 KB Invalid number of links.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 12500 KB Invalid number of links.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 12500 KB Invalid number of links.
2 Halted 0 ms 0 KB -