제출 #477377

#제출 시각아이디문제언어결과실행 시간메모리
477377LoboNetwork (BOI15_net)C++17
100 / 100
495 ms115372 KiB
#include <bits/stdc++.h>
 
using namespace std;

const long long INFll = (long long) 1e18 + 10;
const int INFii = (int) 1e9 + 10;
typedef long long ll;
typedef int ii;
typedef long double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

#define maxn 3300000

ii n, gr[maxn];
vector<ii> ans, g[maxn];

void dfs(ii u, ii ant) {
    if(gr[u] == 1) {
        ans.pb(u);
    }

    for(auto v : g[u]) {
        if(v == ant) continue;

        dfs(v,u);
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);

    //freopen("in.in", "r", stdin);

    cin >> n;

    for(ii i = 0; i < n-1; i++) {
        ii u, v; cin >> u >> v;

        gr[u]++;
        gr[v]++;
        g[u].pb(v);
        g[v].pb(u);
    }

    dfs(1,1);
    
    cout << (ans.size()+1)/2 << endl;

    for(ii i = 0; i < ans.size()/2; i++) {
        cout << ans[i] << " " << ans[i+ans.size()/2 + ans.size()%2] << endl;
    }

    if(ans.size()%2 == 1) {
        cout << ans[ans.size()/2] << " ";
        if(ans[ans.size()/2] != 1) cout << 1 << endl;
        else cout << 2 << endl;
    }

}

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

net.cpp: In function 'int main()':
net.cpp:54:21: warning: comparison of integer expressions of different signedness: 'ii' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for(ii i = 0; i < ans.size()/2; i++) {
      |                   ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...