Submission #405193

#TimeUsernameProblemLanguageResultExecution timeMemory
405193T0p_Network (BOI15_net)C++14
0 / 100
9 ms11960 KiB
#include <bits/stdc++.h>
using namespace std;

int sz;
vector<int> g[500005], leaf;

void dfs(int u, int p)
{
	if(g[u].size() == 1) leaf.push_back(u), sz++;
	for(auto x : g[u]) if(x != p) dfs(x, u);
}

int main()
{
	int n;
	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);
	}
	dfs(1, 0);
	printf("%d\n",(sz+1)/2);
	for(int i=0 ; i<sz ; i+=2)
		printf("%d %d\n",leaf[i],leaf[i+1]);
	if(sz%2) printf("%d %d\n",leaf[sz-1],leaf[0]);
	return 0;
}

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  scanf(" %d",&n);
      |  ~~~~~^~~~~~~~~~
net.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   scanf(" %d %d",&u,&v);
      |   ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...