답안 #988876

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988876 2024-05-26T14:19:18 Z NoLove 경주 (Race) (IOI11_race) C++14
컴파일 오류
0 ms 0 KB
#include "race.h"
/**
 *    author : Lăng Trọng Đạt
 *    created: 26-05-2024 
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int long long
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;
using vi = vector<int>;
#define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
void mx(int& a, int b) { if (b > a) a = b; }
void mi(int& a, int b) { if (b < a) a = b; }
#define si(x) (int)(x.size())
const int INF = 1e18;
const int MOD = 1e9 + 7;

const int MAXN = 5e5 + 5;
int g[MAXN];
int n, ans = INF, k;
vector<pii> adj[MAXN];
map<int, int> md[MAXN]; // md[v][l] = độ sâu lớn nhất khi đi khoảng cách từ node đó đến root đúng = l

void dfs(int v, int prv, int len, int d) {
    md[v][len] = d;
    for (auto[u, l] : adj[v]) {
        if (u == prv) continue;
        dfs(u, v, len + l, d + 1);
        if (si(md[u]) > si(md[v])) swap(md[u], md[v]);
        // x + y - 2 * len = k
        // length = depth + depth_y - 2*d
        for (auto[x, depth] : md[u]) {
            if (md[v].count(k + 2*len - x)) {
                mi(ans, depth + md[v][k + 2*len - x] - 2*d);
            }
        }
        for (auto[x, depth] : md[u]) {
            if (md[v].count(x)) {
                mi(md[v][x], depth);
            } else {
                md[v][x] = depth;
            }
        }
    }
    db(v, md[v])
}
int best_path(int N, int K, int H[][2], int L[])
{
    k = K;
    FOR(i, 0, N - 2) {
        adj[H[i][0]].pb({H[i][1], L[i]});
        adj[H[i][1]].pb({H[i][0], L[i]});
    }
    dfs(1, -1, 0, 0);

    db(ans);
    return (ans == INF ? -1 : ans);
}

Compilation message

race.cpp: In function 'void dfs(long long int, long long int, long long int, long long int)':
race.cpp:34:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   34 |     for (auto[u, l] : adj[v]) {
      |              ^
race.cpp:40:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   40 |         for (auto[x, depth] : md[u]) {
      |                  ^
race.cpp:45:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |         for (auto[x, depth] : md[u]) {
      |                  ^
race.cpp: In function 'long long int best_path(long long int, long long int, long long int (*)[2], long long int*)':
race.cpp:19:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   19 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
race.cpp:58:5: note: in expansion of macro 'FOR'
   58 |     FOR(i, 0, N - 2) {
      |     ^~~
/usr/bin/ld: /tmp/cc166T9U.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