Submission #394619

#TimeUsernameProblemLanguageResultExecution timeMemory
394619ali_tavakoliNetwork (BOI15_net)C++14
0 / 100
2 ms2636 KiB
//In The Name Of Allah #include<bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define F first #define S second //#pragma GCC optimize("Ofast") const int maxn = 1e5 + 5; int n; vector<int> adj[maxn], leaf; int main() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for(int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; adj[a].pb(b); adj[b].pb(a); } for(int i = 1; i <= n; i++) if(adj[i].size() == 1) leaf.pb(i); cout << (leaf.size() + 1) / 2 << '\n'; for(int i = 0; i < leaf.size(); i += 2) { if(i + 1 == leaf.size()) { if(leaf[i] == 1) cout << 1 << " " << 2 << '\n'; else cout << leaf[i] - 1 << " " << leaf[i] << '\n'; } cout << leaf[i] << " " << leaf[i + 1] << '\n'; } } /* 6 1 2 2 3 2 4 5 4 6 4 */

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:34:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |  for(int i = 0; i < leaf.size(); i += 2)
      |                 ~~^~~~~~~~~~~~~
net.cpp:36:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   if(i + 1 == leaf.size())
      |      ~~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...