Submission #81557

# Submission time Handle Problem Language Result Execution time Memory
81557 2018-10-25T10:08:10 Z arman_ferdous Network (BOI15_net) C++17
0 / 100
12 ms 12156 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 5e5+10;
int n, d[N];
vector<int> g[N], leaf;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // use mt19937_64 for 64 bit
int Rand(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }

int main() {
	scanf("%d", &n);
	for(int i = 1; i < n; i++) {
		int u, v; scanf("%d %d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
		d[u]++, d[v]++;
	}
	for(int i = 1; i <= n; i++) if(d[i] == 1)
		leaf.push_back(i);

	int sz = leaf.size();
	for(int i = 0; i < sz; i++)
		swap(leaf[i], leaf[Rand(0,sz-1)]);
	
	printf("%d\n", (int)ceil(sz/2.));
	for(int i = 0; i < sz; i+=2) {
		if(i+1 < sz) printf("%d %d\n", leaf[i], leaf[i+1]);
		else printf("%d %d\n", leaf[i], leaf[0]);
	}
	return 0;	
}

Compilation message

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