Submission #151229

#TimeUsernameProblemLanguageResultExecution timeMemory
151229Charis02Network (BOI15_net)C++14
100 / 100
578 ms48664 KiB
#include<iostream> #include<stdio.h> #include<vector> #include<cmath> #include<queue> #include<string.h> #include<map> #include<set> #include<algorithm> #define ll long long #define pi pair < ll,ll > #define mp(a,b) make_pair(a,b) #define rep(i,a,b) for(int i = a;i < b;i++) #define N 500004 #define INF 1e9+7 using namespace std; ll n,a,b; vector < vector < ll > > graph(N); vector < ll > res; void dfs(ll cur,ll par) { if(graph[cur].size() == 1) { res.push_back(cur); } rep(i,0,graph[cur].size()) { if(graph[cur][i] == par) continue; dfs(graph[cur][i],cur); } return; } int main() { ios_base::sync_with_stdio(false); cin >> n; rep(i,0,n-1) { cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } dfs(1,1); ll half = res.size()/2 + res.size()%2; ll sz = res.size(); cout << half << endl; rep(i,0,half) { cout << res[i] << " "<< res[(i+half)%sz] << "\n"; } return 0; }

Compilation message (stderr)

net.cpp: In function 'void dfs(long long int, long long int)':
net.cpp:13:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,a,b) for(int i = a;i < b;i++)
net.cpp:30:9:
     rep(i,0,graph[cur].size())
         ~~~~~~~~~~~~~~~~~~~~~       
net.cpp:30:5: note: in expansion of macro 'rep'
     rep(i,0,graph[cur].size())
     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...