제출 #904918

#제출 시각아이디문제언어결과실행 시간메모리
904918a_l_i_r_e_z_a경주 (Race) (IOI11_race)C++14
컴파일 에러
0 ms0 KiB
// In the name of God

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
#define len(x) ((int)(x).size())

const int maxn = 2e5 + 5, maxk = 1e6  + 5;
const int inf = 1e9 + 7;
ll n, k, ans = inf, sz[maxn], h[maxn], mn[maxk];
vector<pii> adj[maxn];
vector<int> vec;
bool mark[maxn];

void get_sz(int v, int p = -1){
    sz[v] = 1;
    for(auto [u, w]: adj[v]){
        if(u != p && !mark[u]){
            get_sz(u, v);
            sz[v] += sz[u];
        }
    }
}

int find(int v, int s, int p = -1){
    for(auto [u, w]: adj[v]) if(u != p && !mark[u] && sz[u] * 2 > s) return find(u, s, v);
    return v;
}

void dfs(int v, int h1, int h2, int p, bool keep){
    if(h2 > k) return;
    if(keep){
        smin(mn[h2], 1ll * h1);
        vec.pb(h2);
    }
    else smin(ans, h1 + mn[k - h2]);
    for(auto [u, w]: adj[v]) if(u != p && !mark[u]) dfs(u, h1 + 1, h2 + w, v, keep);
}

void centroid_decomp(int v = 0){
    get_sz(v);
    v = find(v, sz[v]);
    mn[0] = 0;
    for(auto [u, w]: adj[v]){
        if(!mark[u]){
            dfs(u, 1, w, v, 0);
            dfs(u, 1, w, v, 1);
        }
    }
    mn[0] = inf;
    for(auto u: vec) mn[u] = inf;
    vec.clear();
    mark[v] = 1;
    for(auto [u, w]: adj[v]) if(!mark[u]) centroid_decomp(u);
} 

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    fill(mn, mn + maxk, inf);
    cin >> n >> k;
    for(int i = 0; i < n - 1; i++){
        int u, v, w; cin >> u >> v >> w;
        adj[u].pb(mp(v, w));
        adj[v].pb(mp(u, w));
    }
    centroid_decomp();
    cout << (ans >= inf ? -1 : ans) << '\n';

    return 0;
}

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

race.cpp: In function 'void get_sz(int, int)':
race.cpp:29:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   29 |     for(auto [u, w]: adj[v]){
      |              ^
race.cpp: In function 'int find(int, int, int)':
race.cpp:38:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   38 |     for(auto [u, w]: adj[v]) if(u != p && !mark[u] && sz[u] * 2 > s) return find(u, s, v);
      |              ^
race.cpp: In function 'void dfs(int, int, int, int, bool)':
race.cpp:49:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   49 |     for(auto [u, w]: adj[v]) if(u != p && !mark[u]) dfs(u, h1 + 1, h2 + w, v, keep);
      |              ^
race.cpp: In function 'void centroid_decomp(int)':
race.cpp:56:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   56 |     for(auto [u, w]: adj[v]){
      |              ^
race.cpp:66:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   66 |     for(auto [u, w]: adj[v]) if(!mark[u]) centroid_decomp(u);
      |              ^
/usr/bin/ld: /tmp/cccDghuU.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cclk0w5T.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cclk0w5T.o: in function `main':
grader.cpp:(.text.startup+0x28): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status