Submission #234557

#TimeUsernameProblemLanguageResultExecution timeMemory
234557nishkarshNetwork (BOI15_net)C++14
100 / 100
577 ms63072 KiB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
vi adj[upperlimit];
bool visited[upperlimit];
vi leaves;
void dfs(int node){
	visited[node]=true;
	int n=adj[node].size();
	if(n==1) leaves.pb(node);
	for(int i = 0; i < n; i++) if(! visited[adj[node][i]]) dfs(adj[node][i]);
}
int main() {
//	freopen(".in","r",stdin);freopen(".out","w",stdout);
	int n,a,b;
	sd(n);
	for(int i = 1; i < n; i++){
		sd(a);sd(b);
		adj[a].pb(b);adj[b].pb(a);
	}
	int m;
	for(int i = 1; i <= n; i++){
		m=adj[i].size();
		if(m!=1){dfs(m);break;}
	}
	m=leaves.size();
	int gg=m/2;
	pdn(m-gg);
	for(int i = 0; i+gg<m; i++){
		pds(leaves[i]);pdn(leaves[i+gg]);
	}
	return 0;
}

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:12:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define sd(x) scanf("%d",&x)
               ~~~~~^~~~~~~~~
net.cpp:50:2: note: in expansion of macro 'sd'
  sd(n);
  ^~
net.cpp:12:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define sd(x) scanf("%d",&x)
               ~~~~~^~~~~~~~~
net.cpp:52:3: note: in expansion of macro 'sd'
   sd(a);sd(b);
   ^~
net.cpp:12:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define sd(x) scanf("%d",&x)
               ~~~~~^~~~~~~~~
net.cpp:52:9: note: in expansion of macro 'sd'
   sd(a);sd(b);
         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...