Submission #967365

# Submission time Handle Problem Language Result Execution time Memory
967365 2024-04-22T03:13:35 Z Pring Dreaming (IOI13_dreaming) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;

namespace {
    const int MXN = 100005;
    int n, m, len;
    vector<pii> edge[MXN];
    vector<int> rt;
    bitset<MXN> b;
    vector<int> now, A;
    int ans;

    struct P {
        pii a[2];
        void init() {
            a[0] = mp(0, 0);
            a[1] = mp(0, 0);
        }
        void add(pii x) {
            if (x >= a[0]) {
                a[1] = a[0];
                a[0] = x;
            } else a[1] = max(a[1], x);
        }
        int get(int x = 0) {
            return (x == a[0].sc ? a[1].fs : a[0].fs);
        }
    } dp[MXN];

    void DFS1(int id, int par) {
        b[id] = true;
        now.push_back(id);
        dp[id].init();
        for (auto &[w, i] : edge[id]) {
            if (i == par) continue;
            DFS1(i, id);
            dp[id].add(mp(dp[i].get() + w, i));
        }
    }

    void DFS2(int id, int par, int ww) {
        if (par) dp[id].add(mp(dp[par].get(id) + ww, par));
        for (auto &[w, i] : edge[id]) {
            if (i == par) continue;
            DFS2(i, id, w);
        }
    }

    void DP(int rt) {
        debug(rt);
        DFS1(rt, 0);
        DFS2(rt, 0, 0);
    }

    pii calc() {
        int big = 0, sml = INT_MAX;
        for (auto &i : now) {
            big = max(big, dp[i].get());
            sml = min(sml, dp[i].get());
        }
        return mp(big, sml);
    }

    int solve() {
        FOR(i, 1, n + 1) {
            if (b[i]) continue;
            DP(i);
            auto [big, a] = calc();
            ans = max(ans, big);
            A.push_back(a);
            now.clear();
        }
        debug(ans);
        // assert(A.size() == 2);
        // ans = max(ans, A[0] + A[1] + len);
        // cout << "A: ";
        // for (auto &i : A) cout << i << ' ';
        // cout << '\n';
        if (A.size() == 1) return ans;
        if (A.size() == 2) return max(ans, A[0] + A[1] + len);
        sort(A.begin(), A.end(), greater<int>());
        return max(ans, max(A[0] + A[1] + len, A[1] + A[2] + 2 * len));
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    ::n = N;
    ::m = M;
    ::len = L;
    FOR(i, 0, M) {
        edge[++A[i]].push_back(mp(T[i], ++B[i]));
        edge[B[i]].push_back(mp(T[i], A[i]));
    }
    return solve();
}

#ifdef MIKU
int a[MXN], bb[MXN], t[MXN];
void miku() {
    int n, m, l;
    cin >> n >> m >> l;
    FOR(i, 0, m) {
        cin >> a[i] >> bb[i] >> t[i];
    }
    cout << travelTime(n, m, l, a, bb, t) << '\n';
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    miku();
    return 0;
}
#endif

Compilation message

dreaming.cpp: In function 'void {anonymous}::DP(int)':
dreaming.cpp:11:20: warning: statement has no effect [-Wunused-value]
   11 | #define debug(...) 39
      |                    ^~
dreaming.cpp:67:9: note: in expansion of macro 'debug'
   67 |         debug(rt);
      |         ^~~~~
dreaming.cpp: In function 'int {anonymous}::solve()':
dreaming.cpp:11:20: warning: statement has no effect [-Wunused-value]
   11 | #define debug(...) 39
      |                    ^~
dreaming.cpp:90:9: note: in expansion of macro 'debug'
   90 |         debug(ans);
      |         ^~~~~
/usr/bin/ld: /tmp/ccIPT82T.o: in function `main':
grader.c:(.text.startup+0xd1): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status