제출 #544319

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

#define int ll
#define endl '\n'

#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define re resize
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define loop(i, n) for(int i = 0; i < n; i++)
#define loop1(i, n) for(int i = 1; i <= n; i++)
#define print(x) cout << #x << ": " << x << endl

typedef long long ll;
typedef vector<int> vi;
typedef array<int, 2> ii;
typedef array<int, 3> ti;
typedef vector<ii> vii;
typedef vector<ti> vti;
typedef priority_queue<int> pq;

template<class T> bool ckmin(T&a, T b) { bool B = a > b; a = min(a, b); return B; }
template<class T> bool ckmax(T&a, T b) { bool B = a < b; a = max(a, b); return B; }

const int inf = 1e17;
const int maxn = 5e5+5;

vi adj[maxn];

void solve() {
    
    int n; cin >> n;
    loop1(i, n-1) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    vi leaves;
    loop1(i, n)
        if(adj[i].size() == 2)
            leaves.pb(i);

    cout << (leaves.size()+1) / 2 << endl;
    loop(i, leaves.size()/2)
        cout << leaves[i*2] << " " << leaves[i*2+1];
    if(leaves.size() & 1)
        cout << leaves[leaves.size()-1] << " " << leaves[leaves.size()-2];

}

signed main() {

    fast_io;

    int t = 1; //cin >> t;
    while(t--)
        solve();

    cout << flush;

    return 0;

}

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

net.cpp: In function 'void solve()':
net.cpp:13:37: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 | #define loop(i, n) for(int i = 0; i < n; i++)
......
   49 |     loop(i, leaves.size()/2)
      |          ~~~~~~~~~~~~~~~~~~          
net.cpp:49:5: note: in expansion of macro 'loop'
   49 |     loop(i, leaves.size()/2)
      |     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...