Submission #580182

# Submission time Handle Problem Language Result Execution time Memory
580182 2022-06-20T17:01:21 Z Omar_Elgedawy Network (BOI15_net) C++14
0 / 100
8 ms 11988 KB
#include <bits/stdc++.h>
using namespace std;
#define cin(vec)        for(auto& i : vec) cin >> i
#define cout(vec)       for(auto& i : vec) cout << i << " "; cout << "\n";
#define fast            ios::sync_with_stdio(0);cin.tie(0);
#define loop(i,a,b)     for (int i = a; i < b; i++)
#define F               first
#define S               second
#define pb(n)           push_back(n)
#define pf(n)           push_front(n)
#define dci(d)          fixed<<setprecision(d)
#define sp              ' '
#define el              '\n'
#define all(v)          v.begin(),v.end()
#define int             long long
int dx[8]= {0,0,1,-1,-1,1,1,-1};
int dy[8]= {-1,1,0,0,-1,1,-1,1};
int const N=5e5+5,M=1e3+1,Mod=1e9+7;
vector<int>adj[N];
int n,dep[N];
void testcase(int h){
  cin>>n;
  for(int i=0;i<n-1;i++){
    int u,v;cin>>u>>v;
    adj[u].pb(v);
    adj[v].pb(u);
    dep[u]++;
    dep[v]++;
  }
  deque<pair<int,int>>leaf,ans;
  for(int i=1;i<=n;i++){
    if(dep[i]==1){
      leaf.push_back({adj[i][0],i});
    }
  }
  sort(all(leaf));
  if(leaf.size()%2){
    ans.push_back({leaf[0].S,leaf[leaf.size()-1].S});
    leaf.pop_back();
  }
  while(leaf.size()){
    ans.push_back({leaf.back().S,leaf.front().S});
    leaf.pop_back();
    leaf.pop_front();
  }
  cout<<ans.size()<<el;
  for(int i=0;i<ans.size();i++){
    cout<<ans[i].F<<' '<<ans[i].S<<el;
  }
}
int32_t main()
{
  // fast
  testcase(1);
  // int tc;cin>>tc;for(int i=1;i<=tc;i++)testcase(i);
  return 0;
}

Compilation message

net.cpp: In function 'void testcase(long long int)':
net.cpp:47:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for(int i=0;i<ans.size();i++){
      |               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11988 KB Output is correct
2 Incorrect 7 ms 11988 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11988 KB Output is correct
2 Incorrect 7 ms 11988 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11988 KB Output is correct
2 Incorrect 7 ms 11988 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -