제출 #770816

#제출 시각아이디문제언어결과실행 시간메모리
770816nasam경주 (Race) (IOI11_race)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
#define ll long long
#define FOR(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define FOD(i,b,a) for (int i = (b), _a = (a); i >= _a; i--)
#define FORE(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))
#define CNTBIT(x) __builtin_popcount(x)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define left ___left
#define right ___right
#define pii pair<int, int>
#define DEBUG(n, a) FOR (i, 1, n) cout << a[i] << ' '; cout << endl;
#define lob lower_bound // >=
#define upb upper_bound // >
#define endl "\n"
#define NAME "main"

using namespace std;

template<class X, class Y> bool maximize(X &x, Y y){ if (x < y){ x = y; return true; } return false; }
template<class X, class Y> bool minimize(X &x, Y y){ if (x > y){ x = y; return true; } return false; }

#define  gogobruhbruh  ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define  file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }

int MOD = 1e9 + 7;

void add(int &a, int b){ if ((a += b) >= MOD) a -= MOD; }
int sub(int a, int b){ if ((a -= b) < 0) a += MOD; return a; }
int muti(int a, int b){ return (1LL * a * b) % MOD; }
int Pow(int x, int y){ int res = 1; for (; y; y >>= 1){ if (y & 1) res = muti(res, x); x = muti(x, x); } return res; }

const int K = 1e6 + 7;
const int MAX = 2e5 + 7;
const int INF = 1e9 + 7;

int num, target, res = INF;
vector<pii> edge[MAX], tmp;
int sz[MAX], dp[K], exist[K], type;
bool del[MAX];

struct CD {
    void addEdge(int u, int v, int cost){
        edge[u].pb({v, cost});
        edge[v].pb({u, cost});
    }

    void dfs(int u, int pre){
        sz[u] = 1;
        for (auto[v, cost] : edge[u])
            if (!del[v] && v != pre)
                dfs(v, u),
                sz[u] += sz[v];
    }

    int centroid(int u, int pre, int n){
        for (auto[v, cost] : edge[u])
            if (!del[v] && v != pre && sz[v] > n)
                return centroid(v, u, n);
        return u;
    }

    void dfs2(int u, int pre, int dep, int len){
        if (dep > target)
            return;
        tmp.pb({dep, len});
        if (exist[target - dep] == type)
            minimize(res, len + dp[target - dep]);
        for (auto[v, cost] : edge[u])
            if (!del[v] && v != pre)
                dfs2(v, u, dep + cost, len + 1);
    }

    void build(int u){
        dfs(u, -1);
        int root = centroid(u, -1, sz[u] >> 1);
        exist[0] = ++type;
        for (auto[v, cost] : edge[root]){
            dfs2(v, root, cost, 1);
            for (auto[dep, len] : tmp)
                if (exist[dep] < type || (exist[dep] == type && dp[dep] > len))
                    exist[dep] = type,
                    dp[dep] = len;
            tmp.clear();
        }
        del[root] = 1;
        for (auto[v, cost] : edge[root])
            if (!del[v])
                build(v);
    }
} cd;

void solve(){
    cd.build(1);
    if (res == INF)
        res = -1;
    printf("%d", res);
}

void read(){
    scanf("%d %d", &num, &target);
    FOR (i, 2, num){
        static int u, v, cost;
        scanf("%d %d %d", &u, &v, &cost);
        cd.addEdge(++u, ++v, cost);
    }
}

int main(){
    int test = 1;
//    cin >> test;
    while (test--)
        read(),
        solve();
}

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

race.cpp: In member function 'void CD::dfs(int, int)':
race.cpp:55:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   55 |         for (auto[v, cost] : edge[u])
      |                  ^
race.cpp: In member function 'int CD::centroid(int, int, int)':
race.cpp:62:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   62 |         for (auto[v, cost] : edge[u])
      |                  ^
race.cpp: In member function 'void CD::dfs2(int, int, int, int)':
race.cpp:74:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   74 |         for (auto[v, cost] : edge[u])
      |                  ^
race.cpp: In member function 'void CD::build(int)':
race.cpp:83:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   83 |         for (auto[v, cost] : edge[root]){
      |                  ^
race.cpp:85:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   85 |             for (auto[dep, len] : tmp)
      |                      ^
race.cpp:92:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   92 |         for (auto[v, cost] : edge[root])
      |                  ^
race.cpp: In function 'void read()':
race.cpp:106:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |     scanf("%d %d", &num, &target);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
race.cpp:109:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |         scanf("%d %d %d", &u, &v, &cost);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cc3pvUvo.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccaeG2Zp.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccaeG2Zp.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