Submission #716752

#TimeUsernameProblemLanguageResultExecution timeMemory
716752Spade1Network (BOI15_net)C++14
100 / 100
430 ms50040 KiB
#pragma GCC optimize("O3") #include<bits/stdc++.h> //#include <grader.h> #define pii pair<int, int> #define pll pair<long long, long long> #define ll long long #define ld long double #define st first #define nd second #define pb push_back #define INF INT_MAX #define db double using namespace std; const int N = 5e5 + 10; vector<int> v; vector<int> adj[N]; void dfs(int i, int prt) { for (auto j : adj[i]) if (j != prt) dfs(j, i); if (adj[i].size() == 1) v.pb(i); } void solve() { int n; cin >> n; for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } int root; for (int i = 1; i <= n; ++i) if (adj[i].size() > 1) root = i; dfs(root, 0); int sz = v.size(); cout << (sz+1)/2 << '\n'; for (int i = 0; i < sz/2; ++i) { cout << v[i] << " " << v[i+sz/2] << '\n'; } if (sz&1) cout << v[sz-1] << " " << v[0] << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }

Compilation message (stderr)

net.cpp: In function 'void solve()':
net.cpp:31:9: warning: 'root' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |     int root;
      |         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...