제출 #399531

#제출 시각아이디문제언어결과실행 시간메모리
399531cpp219Network (BOI15_net)C++14
100 / 100
631 ms118316 KiB
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include<bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 5e5 + 9;
const ll inf = 1e9 + 7;
const ll Log2 = 21;
vector<ll> g[N];
deque<ll> leaf;
vector<LL> ans;
ll n,x,y,root,pos[N],d[N],par[N][Log2];
ll now;
void DFS(ll u,ll p){
    pos[u] = now; now++;
    for (ll i = 1;i < Log2;i++) if ((1 << u) <= d[u])
        par[u][i] = par[par[u][i - 1]][i - 1];
    for (auto i : g[u]){
        if (i != p){
            d[i] = d[u] + 1; par[i][0] = u;
            DFS(i,u);
        }
    }
}

bool lf(ll x,ll y){
    return pos[x] < pos[y];
}

void out(){
    for (auto i : leaf) cout<<i<<" "; exit(0);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        //freopen(task".out","w",stdout);
    }
    cin>>n;
    for (ll i = 1;i < n;i++){
        cin>>x>>y;
        g[x].push_back(y); g[y].push_back(x);
    }
    for (ll i = 1;i <= n;i++){
        if (g[i].size() > 1) root = i;
        else leaf.push_back(i);
    }
    DFS(root,0); sort(leaf.begin(),leaf.end(),lf);
    ll sz = (leaf.size() + 1) / 2,inc = leaf.size()/2;
    cout<<sz<<"\n";
    for (ll i = 0;i < sz;i++) cout<<leaf[i]<<" "<<leaf[i + inc]<<"\n";
}

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

net.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
net.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
net.cpp: In function 'void out()':
net.cpp:37:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   37 |     for (auto i : leaf) cout<<i<<" "; exit(0);
      |     ^~~
net.cpp:37:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   37 |     for (auto i : leaf) cout<<i<<" "; exit(0);
      |                                       ^~~~
net.cpp: In function 'int main()':
net.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   44 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...