제출 #750502

#제출 시각아이디문제언어결과실행 시간메모리
750502mat_vNetwork (BOI15_net)C++14
100 / 100
465 ms163316 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


int n;
vector<int> graf[5000005];
vector<int> lf;

void dfs(int x, int y){
    bool ima = 0;
    for(auto c:graf[x]){
        if(c == y)continue;
        ima = 1;
        dfs(c, x);
    }
    if(!ima)lf.pb(x);
}


int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> n;
    ff(i,1,n - 1){
        int a,b;
        cin >> a >> b;
        graf[a].pb(b);
        graf[b].pb(a);
    }
    int poc = 1;
    ff(i,1,n){
        if(graf[i].size()>1)poc = i;
    }
    dfs(poc,0);


    int vel = lf.size();
    cout << (vel+1) / 2 << "\n";
    ff(i,0,(vel/2)-1)cout << lf[i] << " " << lf[i + vel/2] << "\n";
    if(vel&1)cout << lf[0] << " " << lf[vel - 1] << "\n";

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

net.cpp: In function 'int main()':
net.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
net.cpp:44:5: note: in expansion of macro 'ff'
   44 |     ff(i,1,n - 1){
      |     ^~
net.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
net.cpp:51:5: note: in expansion of macro 'ff'
   51 |     ff(i,1,n){
      |     ^~
net.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
net.cpp:59:5: note: in expansion of macro 'ff'
   59 |     ff(i,0,(vel/2)-1)cout << lf[i] << " " << lf[i + vel/2] << "\n";
      |     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...