Submission #69457

# Submission time Handle Problem Language Result Execution time Memory
69457 2018-08-21T01:06:31 Z kingpig9 Network (BOI15_net) C++11
0 / 100
15 ms 12136 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

#define debug(...) fprintf(stderr, __VA_ARGS__)
//#define debug(...)
#define all(v) (v).begin(), (v).end()
#define fillchar(a, s) memset((a), (s), sizeof(a))
#define fi first
#define se second

int N;
vector<int> adj[500010];
vector<int> leaves;

void dfs (int x, int p) {
	if (adj[x].size() == 1) {
		leaves.push_back(x);
	}
	for (int y : adj[x]) {
		if (y != p) {
			dfs(y, x);
		}
	}
}

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

	int root = 1;
	while (adj[root].size() == 1) {
		root++;
	}
	dfs(root, -1);

	vector<pii> ans;
	for (int i = 0, j = leaves.size() - 1; i < j; i++, j--) {
		ans.push_back({leaves[i], leaves[j]});
	}

	if (leaves.size() % 2) {
		ans.push_back({leaves[leaves.size() / 2], leaves[0]});
	}

	printf("%lu\n", ans.size());
	for (pii p : ans) {
		printf("%d %d\n", p.fi, p.se);
	}
}

Compilation message

net.cpp: In function 'int main()':
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:33:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12084 KB Output is correct
2 Incorrect 15 ms 12136 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 12084 KB Output is correct
2 Incorrect 15 ms 12136 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 12084 KB Output is correct
2 Incorrect 15 ms 12136 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -