Submission #394757

#TimeUsernameProblemLanguageResultExecution timeMemory
394757Hossein8320Network (BOI15_net)C++17
100 / 100
492 ms47656 KiB
//That's what she said #include <bits/stdc++.h> #define int long long #define pb push_back #define F first #define S second using namespace std; const int maxn = 5e5 + 9, modn = 1e9 + 7; int n, m, v, u; vector <int> barg, adj[maxn]; void dfs(int v, int par) { if(adj[v].size() == 1) barg.pb(v); for(auto i : adj[v]) if(i != par) dfs(i, v); } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n; for(int i = 1; i < n; i++) cin >> v >> u, adj[v].pb(u), adj[u].pb(v); dfs(1, 1); cout << (barg.size() + 1) / 2 << '\n'; int s = barg.size() / 2; for(int i = 0; i < s; i++) cout << barg[i] << " " << barg[i + s] << '\n'; if(s != (barg.size() + 1) / 2) cout << barg[2 * s] << " " << barg[0] << '\n'; return 0; }

Compilation message (stderr)

net.cpp: In function 'int32_t main()':
net.cpp:25:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     if(s != (barg.size() + 1) / 2) cout << barg[2 * s] << " " << barg[0] << '\n';
      |        ~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...