답안 #765355

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765355 2023-06-24T11:27:58 Z vjudge1 Network (BOI15_net) C++11
63 / 100
6 ms 9940 KB
    /*
Muqalzhar taui
*/
#include <bits/stdc++.h>
#include <iomanip>
 
#define ll long long
#define pb push_back
#define F first
#define S second
#define nl '\n'
#define all(x) x.begin(), x.end()
 
const int N = 2e5 + 7;
const int modd = 1e9 + 7;
const int INF = 1e9 + 7;
const double pi = 3.141592653589793238462643383279502884197;
const double EPS = 0.0000000000001;
using namespace std;
  
int gcd(int a, int b){
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
 
ll binpow(ll a, ll x){
    if(x == 0) return 1;
    if(x % 2 == 0){
        ll y = binpow(a, x / 2);
        return (y * y);
    }
    else{
        return (binpow(a, x - 1) * a);
    }
}

ll n;
vector <ll> v[N];
vector <ll> s;
vector <ll> l;
vector <ll> r;
bool used[N];

void dfs(ll x){
    used[x] = 1;
    if(v[x].size() == 1){
        s.pb(x);
    }
    for(auto to : v[x]){
        if(used[to] == 0){
            dfs(to);
        }
    }
}

void Muqaltin(){  
    cin >> n;
    for(int i = 1; i < n; i++){
        int x, y;
        cin >> x >> y;
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs(1);
    for(int i = 0; i < s.size() / 2; i++){
        l.pb(s[i]);
    }
    for(int i = s.size() / 2; i < s.size(); i++){
        r.pb(s[i]);
    }
    cout << max(l.size(), r.size()) << nl;
    for(int i = 0; i < min(l.size(), r.size()); i++){
        cout << l[i] << ' ' << r[i] << nl;
    }
    if(l.size() > r.size()){
        cout << l[l.size() - 1] << " " << l[0] << nl;
    }   
    else if(l.size() < r.size()){
        cout << r[r.size() - 1] << " " << r[0] << nl;
    }
    return;
}
 
int main(){
    // freopen("pails.in", "r", stdin);
    //  freopen("pails.out", "w", stdout);
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
 
    int t = 1;
    // cin >> t;
    while(t--){
        Muqaltin();
    }
    return 0;
}

Compilation message

net.cpp: In function 'void Muqaltin()':
net.cpp:67:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int i = 0; i < s.size() / 2; i++){
      |                    ~~^~~~~~~~~~~~~~
net.cpp:70:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for(int i = s.size() / 2; i < s.size(); i++){
      |                               ~~^~~~~~~~~~
net.cpp:74:22: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   74 |     for(int i = 0; i < min(l.size(), r.size()); i++){
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5024 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 5024 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4980 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 5024 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 5020 KB Output is correct
20 Correct 2 ms 5016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5024 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 5024 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4980 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 5024 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 5020 KB Output is correct
20 Correct 2 ms 5016 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5080 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 2 ms 5076 KB Output is correct
27 Correct 3 ms 5092 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
29 Correct 3 ms 5076 KB Output is correct
30 Correct 2 ms 5024 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 2 ms 5020 KB Output is correct
35 Correct 2 ms 5024 KB Output is correct
36 Correct 3 ms 5024 KB Output is correct
37 Correct 3 ms 5024 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 2 ms 4948 KB Output is correct
40 Correct 2 ms 5024 KB Output is correct
41 Correct 2 ms 4948 KB Output is correct
42 Correct 2 ms 4948 KB Output is correct
43 Correct 2 ms 5076 KB Output is correct
44 Correct 2 ms 5028 KB Output is correct
45 Correct 2 ms 4948 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 2 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 2 ms 5076 KB Output is correct
50 Correct 2 ms 5024 KB Output is correct
51 Correct 2 ms 5020 KB Output is correct
52 Correct 2 ms 5016 KB Output is correct
53 Correct 2 ms 5024 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 3 ms 4948 KB Output is correct
56 Correct 3 ms 4976 KB Output is correct
57 Correct 2 ms 5024 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5024 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 5024 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 2 ms 4980 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 5024 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 5020 KB Output is correct
20 Correct 2 ms 5016 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 3 ms 5076 KB Output is correct
23 Correct 3 ms 5080 KB Output is correct
24 Correct 3 ms 5076 KB Output is correct
25 Correct 3 ms 5076 KB Output is correct
26 Correct 2 ms 5076 KB Output is correct
27 Correct 3 ms 5092 KB Output is correct
28 Correct 3 ms 5076 KB Output is correct
29 Correct 3 ms 5076 KB Output is correct
30 Correct 2 ms 5024 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 2 ms 4948 KB Output is correct
34 Correct 2 ms 5020 KB Output is correct
35 Correct 2 ms 5024 KB Output is correct
36 Correct 3 ms 5024 KB Output is correct
37 Correct 3 ms 5024 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 2 ms 4948 KB Output is correct
40 Correct 2 ms 5024 KB Output is correct
41 Correct 2 ms 4948 KB Output is correct
42 Correct 2 ms 4948 KB Output is correct
43 Correct 2 ms 5076 KB Output is correct
44 Correct 2 ms 5028 KB Output is correct
45 Correct 2 ms 4948 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 2 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 2 ms 5076 KB Output is correct
50 Correct 2 ms 5024 KB Output is correct
51 Correct 2 ms 5020 KB Output is correct
52 Correct 2 ms 5016 KB Output is correct
53 Correct 2 ms 5024 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 3 ms 4948 KB Output is correct
56 Correct 3 ms 4976 KB Output is correct
57 Correct 2 ms 5024 KB Output is correct
58 Correct 3 ms 5076 KB Output is correct
59 Runtime error 6 ms 9940 KB Execution killed with signal 11
60 Halted 0 ms 0 KB -