Submission #765399

# Submission time Handle Problem Language Result Execution time Memory
765399 2023-06-24T12:18:32 Z vjudge1 Network (BOI15_net) C++17
0 / 100
12 ms 23764 KB
/******************
tree-bends-in-youth
//24///06///2023///
******************/
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
const ll N = 1e6 + 1;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;
vector<int>g[N];
vector <int> l;
map<int,int>used;
int tm;
void dfs(int v){
    used[v]=1;
    if(g[v].size() == 1)l.pb(v);
    for(ll to : g[v]){
        if(!used[to]){
            dfs(to);
        }
    }
}
void solve(){
    int n;
    cin >> n;
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        g[x].pb(y);
        g[y].pb(x);
    }
    int r = 0;
    for(int i = 1;i <= n;i++){
        if(g[i].size() > 1){
            r = i;
            break;
        }
    }
    dfs(r);
    int k = (l.size() + 1) / 2;
    cout << k << '\n';
    for(int i = 0;i + k < l.size();i++){
        cout << l[i] << " " << l[i + k] << '\n';
    }
    if(k % 2){
        cout << l[0] << " " << l[k - 1] << '\n';
    }
}
main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	//freopen("censor.in","r",stdin);
	//freopen("censor.out","w",stdout);
    ll T = 1;
    //cin >> T;
    for(ll i = 1;i <= T;i++){
      //  cout << "Case " << i << ":\n";
        solve();
    }
}

Compilation message

net.cpp: In function 'void solve()':
net.cpp:47:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i = 0;i + k < l.size();i++){
      |                   ~~~~~~^~~~~~~~~~
net.cpp: At global scope:
net.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main () {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23764 KB Extra information in the output file
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23764 KB Extra information in the output file
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23764 KB Extra information in the output file
2 Halted 0 ms 0 KB -