Submission #26107

# Submission time Handle Problem Language Result Execution time Memory
26107 2017-06-28T03:28:28 Z bugmenot111 Network (BOI15_net) C++14
0 / 100
0 ms 14800 KB
#include <cstdio>
#include <vector>
#define MAXN 500500
std::vector<int> g[MAXN];
int leaves[MAXN], leaves_top;
void dfs(int v, int p) {
	if(g[v].size() == 1) leaves[leaves_top++] = v;
	for(int c: g[v]) if(c != p) dfs(c, v);
}
int main(void) {
	int n;
	scanf("%d", &n);
	for(int i = 1; i < n; i++) {
		int src, dst;
		scanf("%d%d", &src, &dst);
		src--;
		dst--;
	}
	dfs(0, -1);
	int nv = (leaves_top + 1) / 2;
	printf("%d\n", nv);
	for(int i = 0; i < nv; i++) {
		int src = leaves[i];
		int dst = leaves[(i + nv) % leaves_top];
		src++;
		dst++;
		printf("%d %d\n", src, dst);
	}
	return 0;
}

Compilation message

net.cpp: In function 'int main()':
net.cpp:12:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
net.cpp:15:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &src, &dst);
                            ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 14800 KB Invalid number of links.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 14800 KB Invalid number of links.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 14800 KB Invalid number of links.
2 Halted 0 ms 0 KB -