Submission #197940

# Submission time Handle Problem Language Result Execution time Memory
197940 2020-01-24T11:39:48 Z dndhk Network (BOI15_net) C++14
0 / 100
13 ms 12152 KB
#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]);
		}
	}
}

Compilation message

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 time Memory Grader output
1 Correct 13 ms 12152 KB Output is correct
2 Incorrect 13 ms 12152 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12152 KB Output is correct
2 Incorrect 13 ms 12152 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12152 KB Output is correct
2 Incorrect 13 ms 12152 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -