답안 #24992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
24992 2017-06-19T16:59:52 Z minimario Network (BOI15_net) C++14
0 / 100
0 ms 13736 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX = 500000;
vector<int> g[MAX];
vector<int> order;

void dfs(int u, int p) {
	for (int i : g[u]) {
		if (i == p) { continue; }
		dfs(i, u);
	}
	if (g[u].size() == 1) { order.push_back(u); }
}

int main() {
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);

	int n; scanf("%d", &n);
	for (int i = 0; i < n-1; ++i)
	{
		int u, v; scanf("%d %d", &u, &v);
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0, -1);
	for (int i = 0; i < order.size(); ++i)
	{
		order[i]++;
	}
	printf("%d\n", ((int)order.size()+1)/2);
	for (int i = 0; i < ((int)order.size())/2; ++i) 
	{
		printf("%d %d\n", order[i], order[order.size()-1-i]);
	}
	if (order.size() % 2 == 1) { printf("%d %d\n", order[0], order[order.size()/2]); }
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:30:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < order.size(); ++i)
                    ^
net.cpp:18:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("a.in", "r", stdin);
                             ^
net.cpp:19:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("a.out", "w", stdout);
                               ^
net.cpp:21:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n; scanf("%d", &n);
                        ^
net.cpp:24:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int u, v; scanf("%d %d", &u, &v);
                                   ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 13736 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 13736 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 13736 KB Execution killed because of forbidden syscall [unknown syscall - gap in table] (292)
2 Halted 0 ms 0 KB -