제출 #197940

#제출 시각아이디문제언어결과실행 시간메모리
197940dndhkNetwork (BOI15_net)C++14
0 / 100
13 ms12152 KiB
#include <bits/stdc++.h>

#define pb push_back

using namespace std;

const int MAX_N = 500000;

int N;
vector<int> gp[MAX_N+1];
int r;
vector<int> v;
int p[MAX_N+1], sz[MAX_N+1];

void dfs(int x){
	sz[x] = 1;
	for(int i : gp[x]){
		if(i==p[x])	continue;
		p[i] = x;
		dfs(i);
		sz[x]+=sz[i];
	}
	if(sz[x]==1){
		v.pb(x);
	}
}



int main(){
	scanf("%d", &N);
	for(int i=1; i<N; i++){
		int a, b; scanf("%d%d", &a, &b);
		gp[a].pb(b);
		gp[b].pb(a);
	}
	for(int i=1; i<=N; i++){
		if(gp[i].size()>=2){
			r = i;
			break;
		}
	}
	dfs(r);
	printf("%d\n", (v.size()+1)/2);
	for(int i=0; i<v.size()/2; i++){
		if(i==v.size()-1-i){
			printf("%d %d\n", v[0], v[i]);
		}else{
			printf("%d %d\n", v[i], v[v.size()-1-i]);
		}
	}
}

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

net.cpp: In function 'int main()':
net.cpp:44:31: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n", (v.size()+1)/2);
                 ~~~~~~~~~~~~~~^
net.cpp:45:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<v.size()/2; i++){
               ~^~~~~~~~~~~
net.cpp:46:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(i==v.size()-1-i){
      ~^~~~~~~~~~~~~~
net.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
net.cpp:33:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a, b; scanf("%d%d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...