Submission #240210

#TimeUsernameProblemLanguageResultExecution timeMemory
240210aggu_01000101Network (BOI15_net)C++14
0 / 100
5 ms384 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define int long long #define INF 1000000000000000 #define lchild(i) (i*2 + 1) #define rchild(i) (i*2 + 2) #define mid(l, u) ((l+u)/2) #define x(p) p.first #define y(p) p.second #define MOD 998244353 #define ordered_set tree<pair<int, int>, null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update> using namespace std; map<int, int> mp; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin>>n; for(int i =1 ;i<n;i++){ int u, v; cin>>u>>v; mp[u]++; mp[v]++; } int l = 0; vector<int> v; for(int i = 1;i<=n;i++){ l += (mp[i] == 1); if(mp[i] == 1) v.push_back(i); } l = (l/2) + (l%2); cout<<l<<"\n"; for(int i = 1;i<v.size();i+=2){ cout<<v[i]<<" "<<v[i-1]<<"\n"; } if(v.size()%2 != 0){ cout<<v[v.size() - 2]<<" "<<v[v.size() - 1]<<"\n"; } } /* 5 4 35 100 70 70 45 15 80 40 20 95 20 50 120 10 10 100 60 60 80 0 100 100 10 10 41304 98327 91921 28251 85635 59191 30361 72671 28949 96958 99041 37826 10245 2726 19387 20282 60366 87723 95388 49726 52302 69501 66009 43754 45346 3158 25224 58881 18727 7298 24412 63782 24107 10583 61508 65025 29140 7278 36104 56758 2775 23126 67608 122051 56910 17272 62933 39675 15874 117117 */

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:35:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 1;i<v.size();i+=2){
                   ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...