답안 #220847

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
220847 2020-04-09T05:08:12 Z arnold518 Network (BOI15_net) C++14
0 / 100
13 ms 12032 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 5e5;
const int INF = 987654321;

int N;
vector<int> adj[MAXN+10], V;

void dfs(int now, int bef)
{
	int cnt=0;
	for(int nxt : adj[now])
	{
		if(nxt==bef) continue;
		dfs(nxt, now);
		cnt++;
	}
	if(cnt==0) V.push_back(now);
}

int main()
{
	int i, j;

	scanf("%d", &N);
	for(i=1; i<N; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	for(i=1; i<=N; i++) if(adj[i].size()>1) break;
	int root=i;
	dfs(root, root);
	
	printf("%d\n", (V.size()+1)/2);
	for(i=0; i<V.size()/2; i++) printf("%d %d\n", V[i], V[i+V.size()/2]);
	if(V.size()%2) printf("%d %d\n", root, V.back());
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:43: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:44:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0; i<V.size()/2; i++) printf("%d %d\n", V[i], V[i+V.size()/2]);
           ~^~~~~~~~~~~
net.cpp:28:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
net.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
net.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12032 KB Output is correct
2 Correct 12 ms 12032 KB Output is correct
3 Correct 12 ms 12032 KB Output is correct
4 Correct 11 ms 12032 KB Output is correct
5 Correct 12 ms 12032 KB Output is correct
6 Correct 12 ms 12032 KB Output is correct
7 Incorrect 13 ms 12032 KB Breaking single line is causing network to disconnect.
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12032 KB Output is correct
2 Correct 12 ms 12032 KB Output is correct
3 Correct 12 ms 12032 KB Output is correct
4 Correct 11 ms 12032 KB Output is correct
5 Correct 12 ms 12032 KB Output is correct
6 Correct 12 ms 12032 KB Output is correct
7 Incorrect 13 ms 12032 KB Breaking single line is causing network to disconnect.
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12032 KB Output is correct
2 Correct 12 ms 12032 KB Output is correct
3 Correct 12 ms 12032 KB Output is correct
4 Correct 11 ms 12032 KB Output is correct
5 Correct 12 ms 12032 KB Output is correct
6 Correct 12 ms 12032 KB Output is correct
7 Incorrect 13 ms 12032 KB Breaking single line is causing network to disconnect.
8 Halted 0 ms 0 KB -