답안 #931855

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931855 2024-02-22T12:37:43 Z Erfan1386Y Network (BOI15_net) C++17
0 / 100
3 ms 12124 KB
#include <bits/stdc++.h>
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);
#define what(x) cerr << #x << " is " << x << '\n';
#define kill(x) {cout << x << endl; return 0;}
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define pb push_back
#define ll long long
#define F first
#define S second
const ll inf = 1e18, mod = 1e9 + 7, delta = 1e9 + 9, SQ = 450, P = 6065621;
 
using namespace std;

const int N = 5e5 + 10, LG = 40;
vector<int> adj[N], l;

void dfs (int v, int p = -1) {
  if (adj[v].size() == 1) l.pb(v);
  for (auto u: adj[v])
    if (u - p) dfs(u, v);
}

int main () {
  fast_io;
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  dfs(1);
  cout << ceil(l.size() / 2) << '\n';
  int t = (l.size() + 1) / 2;
  for (int i = 0; i < t; i++)
    cout << l[i] << ' ' << l[i + l.size() / 2] << '\n'; 
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12124 KB Output is correct
2 Correct 3 ms 12124 KB Output is correct
3 Correct 3 ms 12120 KB Output is correct
4 Incorrect 3 ms 12124 KB Invalid number of links.
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12124 KB Output is correct
2 Correct 3 ms 12124 KB Output is correct
3 Correct 3 ms 12120 KB Output is correct
4 Incorrect 3 ms 12124 KB Invalid number of links.
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12124 KB Output is correct
2 Correct 3 ms 12124 KB Output is correct
3 Correct 3 ms 12120 KB Output is correct
4 Incorrect 3 ms 12124 KB Invalid number of links.
5 Halted 0 ms 0 KB -