답안 #220850

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
220850 2020-04-09T05:12:26 Z arnold518 Network (BOI15_net) C++14
100 / 100
548 ms 51956 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", V[0], 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 11 ms 12032 KB Output is correct
2 Correct 11 ms 12032 KB Output is correct
3 Correct 12 ms 12032 KB Output is correct
4 Correct 12 ms 12032 KB Output is correct
5 Correct 11 ms 12032 KB Output is correct
6 Correct 12 ms 12032 KB Output is correct
7 Correct 12 ms 12032 KB Output is correct
8 Correct 12 ms 12032 KB Output is correct
9 Correct 12 ms 12032 KB Output is correct
10 Correct 11 ms 12032 KB Output is correct
11 Correct 12 ms 12032 KB Output is correct
12 Correct 12 ms 12032 KB Output is correct
13 Correct 11 ms 12032 KB Output is correct
14 Correct 12 ms 12032 KB Output is correct
15 Correct 11 ms 12032 KB Output is correct
16 Correct 12 ms 12160 KB Output is correct
17 Correct 12 ms 12032 KB Output is correct
18 Correct 12 ms 12032 KB Output is correct
19 Correct 11 ms 12032 KB Output is correct
20 Correct 11 ms 12032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12032 KB Output is correct
2 Correct 11 ms 12032 KB Output is correct
3 Correct 12 ms 12032 KB Output is correct
4 Correct 12 ms 12032 KB Output is correct
5 Correct 11 ms 12032 KB Output is correct
6 Correct 12 ms 12032 KB Output is correct
7 Correct 12 ms 12032 KB Output is correct
8 Correct 12 ms 12032 KB Output is correct
9 Correct 12 ms 12032 KB Output is correct
10 Correct 11 ms 12032 KB Output is correct
11 Correct 12 ms 12032 KB Output is correct
12 Correct 12 ms 12032 KB Output is correct
13 Correct 11 ms 12032 KB Output is correct
14 Correct 12 ms 12032 KB Output is correct
15 Correct 11 ms 12032 KB Output is correct
16 Correct 12 ms 12160 KB Output is correct
17 Correct 12 ms 12032 KB Output is correct
18 Correct 12 ms 12032 KB Output is correct
19 Correct 11 ms 12032 KB Output is correct
20 Correct 11 ms 12032 KB Output is correct
21 Correct 12 ms 12032 KB Output is correct
22 Correct 13 ms 12160 KB Output is correct
23 Correct 13 ms 12160 KB Output is correct
24 Correct 13 ms 12160 KB Output is correct
25 Correct 13 ms 12160 KB Output is correct
26 Correct 14 ms 12160 KB Output is correct
27 Correct 13 ms 12160 KB Output is correct
28 Correct 13 ms 12160 KB Output is correct
29 Correct 13 ms 12160 KB Output is correct
30 Correct 12 ms 12032 KB Output is correct
31 Correct 14 ms 12160 KB Output is correct
32 Correct 12 ms 12032 KB Output is correct
33 Correct 12 ms 12032 KB Output is correct
34 Correct 13 ms 12032 KB Output is correct
35 Correct 12 ms 12032 KB Output is correct
36 Correct 12 ms 12032 KB Output is correct
37 Correct 12 ms 12160 KB Output is correct
38 Correct 12 ms 12160 KB Output is correct
39 Correct 12 ms 12032 KB Output is correct
40 Correct 12 ms 12032 KB Output is correct
41 Correct 12 ms 12032 KB Output is correct
42 Correct 12 ms 12032 KB Output is correct
43 Correct 12 ms 12160 KB Output is correct
44 Correct 12 ms 12032 KB Output is correct
45 Correct 12 ms 12032 KB Output is correct
46 Correct 12 ms 12160 KB Output is correct
47 Correct 11 ms 12032 KB Output is correct
48 Correct 12 ms 12160 KB Output is correct
49 Correct 12 ms 12160 KB Output is correct
50 Correct 12 ms 12032 KB Output is correct
51 Correct 11 ms 12032 KB Output is correct
52 Correct 12 ms 12032 KB Output is correct
53 Correct 12 ms 12160 KB Output is correct
54 Correct 12 ms 12032 KB Output is correct
55 Correct 13 ms 12032 KB Output is correct
56 Correct 12 ms 12032 KB Output is correct
57 Correct 12 ms 12032 KB Output is correct
58 Correct 14 ms 12160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12032 KB Output is correct
2 Correct 11 ms 12032 KB Output is correct
3 Correct 12 ms 12032 KB Output is correct
4 Correct 12 ms 12032 KB Output is correct
5 Correct 11 ms 12032 KB Output is correct
6 Correct 12 ms 12032 KB Output is correct
7 Correct 12 ms 12032 KB Output is correct
8 Correct 12 ms 12032 KB Output is correct
9 Correct 12 ms 12032 KB Output is correct
10 Correct 11 ms 12032 KB Output is correct
11 Correct 12 ms 12032 KB Output is correct
12 Correct 12 ms 12032 KB Output is correct
13 Correct 11 ms 12032 KB Output is correct
14 Correct 12 ms 12032 KB Output is correct
15 Correct 11 ms 12032 KB Output is correct
16 Correct 12 ms 12160 KB Output is correct
17 Correct 12 ms 12032 KB Output is correct
18 Correct 12 ms 12032 KB Output is correct
19 Correct 11 ms 12032 KB Output is correct
20 Correct 11 ms 12032 KB Output is correct
21 Correct 12 ms 12032 KB Output is correct
22 Correct 13 ms 12160 KB Output is correct
23 Correct 13 ms 12160 KB Output is correct
24 Correct 13 ms 12160 KB Output is correct
25 Correct 13 ms 12160 KB Output is correct
26 Correct 14 ms 12160 KB Output is correct
27 Correct 13 ms 12160 KB Output is correct
28 Correct 13 ms 12160 KB Output is correct
29 Correct 13 ms 12160 KB Output is correct
30 Correct 12 ms 12032 KB Output is correct
31 Correct 14 ms 12160 KB Output is correct
32 Correct 12 ms 12032 KB Output is correct
33 Correct 12 ms 12032 KB Output is correct
34 Correct 13 ms 12032 KB Output is correct
35 Correct 12 ms 12032 KB Output is correct
36 Correct 12 ms 12032 KB Output is correct
37 Correct 12 ms 12160 KB Output is correct
38 Correct 12 ms 12160 KB Output is correct
39 Correct 12 ms 12032 KB Output is correct
40 Correct 12 ms 12032 KB Output is correct
41 Correct 12 ms 12032 KB Output is correct
42 Correct 12 ms 12032 KB Output is correct
43 Correct 12 ms 12160 KB Output is correct
44 Correct 12 ms 12032 KB Output is correct
45 Correct 12 ms 12032 KB Output is correct
46 Correct 12 ms 12160 KB Output is correct
47 Correct 11 ms 12032 KB Output is correct
48 Correct 12 ms 12160 KB Output is correct
49 Correct 12 ms 12160 KB Output is correct
50 Correct 12 ms 12032 KB Output is correct
51 Correct 11 ms 12032 KB Output is correct
52 Correct 12 ms 12032 KB Output is correct
53 Correct 12 ms 12160 KB Output is correct
54 Correct 12 ms 12032 KB Output is correct
55 Correct 13 ms 12032 KB Output is correct
56 Correct 12 ms 12032 KB Output is correct
57 Correct 12 ms 12032 KB Output is correct
58 Correct 14 ms 12160 KB Output is correct
59 Correct 411 ms 36124 KB Output is correct
60 Correct 485 ms 38760 KB Output is correct
61 Correct 12 ms 12032 KB Output is correct
62 Correct 12 ms 12032 KB Output is correct
63 Correct 357 ms 33768 KB Output is correct
64 Correct 16 ms 12544 KB Output is correct
65 Correct 24 ms 14208 KB Output is correct
66 Correct 167 ms 30584 KB Output is correct
67 Correct 548 ms 51320 KB Output is correct
68 Correct 543 ms 51956 KB Output is correct
69 Correct 19 ms 12928 KB Output is correct
70 Correct 104 ms 21228 KB Output is correct
71 Correct 342 ms 42164 KB Output is correct
72 Correct 381 ms 40816 KB Output is correct
73 Correct 107 ms 19188 KB Output is correct
74 Correct 493 ms 37740 KB Output is correct
75 Correct 39 ms 15224 KB Output is correct
76 Correct 359 ms 41812 KB Output is correct
77 Correct 343 ms 41804 KB Output is correct
78 Correct 42 ms 15864 KB Output is correct
79 Correct 544 ms 48760 KB Output is correct
80 Correct 14 ms 12288 KB Output is correct
81 Correct 123 ms 21360 KB Output is correct
82 Correct 413 ms 39632 KB Output is correct
83 Correct 494 ms 37744 KB Output is correct
84 Correct 517 ms 37996 KB Output is correct
85 Correct 540 ms 37744 KB Output is correct
86 Correct 488 ms 38756 KB Output is correct
87 Correct 496 ms 38828 KB Output is correct