Submission #122121

#TimeUsernameProblemLanguageResultExecution timeMemory
122121GustavNetwork (BOI15_net)C++14
0 / 100
2 ms384 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<pi> vpi; typedef vector<vi> vvi; const int inf = 0x3f3f3f3f; const ll linf = 123456789012345678; const ll mod = 998244353; #pragma GCC optimize("Ofast") #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " = " << x << endl int n; vvi conn; int main(){ cin.sync_with_stdio(false); cin.tie(0); cin >> n; conn = vvi(n); for(int i = 0; i < n-1; i++){ int u, v; cin >> u >> v; u--, v--; conn[u].push_back(v); conn[v].push_back(u); } vi u; for(int i = 0; i < n; i++) if(conn[i].size() == 1) u.push_back(i); cout << (u.size()+1)/2 << "\n"; for(int i = 1; i < u.size(); i+=2) cout << u[i]+1 << " " << u[i-1]+1 << "\n"; if(u.size()%2 == 1){ int to = 0; if(u[u.size()-1] == to) to++; if(conn[u[u.size()-1]][0] == to) to++; if(u[u.size()-1] == to) to++; cout << u[u.size()-1]+1 << " " << to+1 << "\n"; } }

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:37:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 1; i < u.size(); i+=2) cout << u[i]+1 << " " << u[i-1]+1 << "\n";
                    ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...