Submission #592528

# Submission time Handle Problem Language Result Execution time Memory
592528 2022-07-09T09:31:49 Z ddy888 Network (BOI15_net) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define fi first
#define si second
#define ar array
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;  
template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)

const int MAXN = 500010;

int n;
int in[MAXN];

vector<int> leaf;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin.exceptions(ios::badbit | ios::failbit);

    cin >> n;
    for (int i = 1; i < n; ++i) {
        int u, v; cin >> u >> v;
        ++in[u], ++in[v];
    }

    for (int i = 1; i <= n; ++i) {
        if (in[i] == 1) leaf.pb(i);
    }

    int ans = ((int)leaf.size() + 1) / 2;
    cout << ans << '\n';
    
    if (ans == 1) {
        cout << leaf[0] << ' ' << leaf[1] << '\n';
        return 0;
    }
    int j = 2;
    for (int i = 0; i < ans; ++i) {
        j %= (int)leaf.size();
        cout << leaf[i] << ' ' << leaf[j++] << '\n';
    }

    return 0;
}   
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Breaking single line is causing network to disconnect.
3 Halted 0 ms 0 KB -