Submission #1265368

#TimeUsernameProblemLanguageResultExecution timeMemory
1265368BlockOGDreaming (IOI13_dreaming)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

// mrrrow meeow :3
// go play vivid/stasis now! it's free on steam

#define fo(i, a, b) for (auto i = (a); i < (b); i++)
#define of(i, a, b) for (auto i = (b); i-- > (a);)
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define be(a) a.begin(), a.end()
using namespace std;

int ____init = [] {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    return 0;
}();

struct Component {
    int diameter;
    int longest;

    Component(int diameter, int longest) : diameter(diameter), longest(longest) {}
};

int vis[100000];
vector<pair<int, int>> adj[100000];

pair<int, int> dfs1(int i) {
    pair<int, int> res;

    queue<pair<int, int>> q;
    q.push({i, 0});
    while (q.size()) {
        auto [i, d] = q.front();
        q.pop();
        res = max(res, {d, i});

        vis[i] = 1;
        for (auto [j, t] : adj[i]) {
            if (vis[j] == 1) continue;
            q.push({j, d + t});
        }
    }

    return res;
}

int dfs2(int i) {
    int res = 0;

    queue<pair<int, int>> q;
    q.push({i, 0});
    while (q.size()) {
        auto [i, d] = q.front();
        q.pop();
        res = max(res, d);

        vis[i] = 2;
        for (auto [j, t] : adj[i]) {
            if (vis[j] == 2) continue;
            q.push({j, d + t});
        }
    }

    return res;
}

int diameter, longest;
int dfs3(int i) {
    int res = 2000000000;

    queue<pair<int, int>> q;
    q.push({i, 0});
    while (q.size()) {
        auto [i, d] = q.front();
        q.pop();
        res = min(res, max(d, diameter - d));

        vis[i] = 3;
        for (auto [j, t] : adj[i]) {
            if (vis[j] == 3) continue;
            q.push({j, d + t});
        }
    }

    return res;
}

int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
    fo(i, 0, m) {
        adj[a[i]].pb({b[i], t[i]});
        adj[b[i]].pb({a[i], t[i]});
    }

    vector<Component> comps;
    fo(i, 0, n) if (!vis[i]) {
        int far = dfs1(i).s;
        diameter = dfs2(far);
        longest = dfs3(far);
        comps.pb(Component(diameter, longest));
    }

    sort(be(comps), [](Component &a, Component &b) { return a.longest < b.longest; });

    Component res = comps.back();
    comps.pop_back();

    for (Component i : comps) {
        res.diameter = max(max(res.diameter, i.diameter), res.longest + l + i.longest);
        res.longest = max(res.longest, i.longest + l);
    }

    return res.diameter;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccfnVIe4.o: in function `main':
grader.c:(.text.startup+0xc4): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status