Submission #1098600


Source Code Expand

#include <bits/stdc++.h>
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl

using Weight = int;
using Capacity = int;
struct Edge {
    int src, dst;
    Weight weight;
    Edge() : src(0), dst(0), weight(0) {}
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
    g[a].emplace_back(a, b, w);
    g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) {
    g[a].emplace_back(a, b, w);
}

Weight bidirectional_dijkstra(const Graph &g, int s, int t){
    if(s == t) return 0;
    constexpr Weight INF = std::numeric_limits<Weight>::max() / 2;
    int n = g.size();
    std::vector<Weight> dist[2];
    dist[0] = dist[1] = std::vector<Weight>(n, INF);
    dist[0][s] = dist[1][t] = 0;
    using state = std::pair<Weight, int>;
    std::priority_queue<state, std::vector<state>, std::greater<state>> q[2];
    q[0].emplace(0, s);
    q[1].emplace(0, t);
    Weight mu = INF;
    while (q[0].size() && q[1].size()) {
        if (q[0].top().first + q[1].top().first >= mu) break;
        int k = q[0].top().first <= q[1].top().first ? 0 : 1;
        Weight d;
        int v;
        std::tie(d, v) = q[k].top();
        q[k].pop();
        if (d < dist[k][v]) continue;
        for (auto &e: g[v]) {
            int w = e.dst;
            if (dist[k][w] > dist[k][v] + e.weight) {
                dist[k][w] = dist[k][v] + e.weight;
                q[k].emplace(dist[k][w], w);
                mu = std::min(mu, dist[k][v] + e.weight + dist[1 - k][w]);
            }
        }
    }
    return mu;
}

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    Graph g(n);
    rep(i, m){
        int a, b, t;
        cin >> a >> b >> t;
        --a; --b;
        add_edge(g, a, b, t);
    }
    int res = 1e9;
    rep(i, n){
        int cand = 0;
        rep(j, n){
            cand = max(cand, bidirectional_dijkstra(g, i, j));
            if(cand > res) break;
        }
        res = min(res, cand);
    }
    cout << res << endl;
}

Submission Info

Submission Time
Task D - バスと避けられない運命
User tubo28
Language C++11 (GCC 4.8.1)
Score 100
Code Size 2429 Byte
Status AC
Exec Time 904 ms
Memory 2908 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 36
Set Name Test Cases
All test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt
Case Name Status Exec Time Memory
sample_01.txt AC 20 ms 924 KB
sample_02.txt AC 18 ms 924 KB
sample_03.txt AC 17 ms 920 KB
test_01.txt AC 19 ms 924 KB
test_02.txt AC 34 ms 924 KB
test_03.txt AC 441 ms 2908 KB
test_04.txt AC 111 ms 920 KB
test_05.txt AC 904 ms 1564 KB
test_06.txt AC 48 ms 1048 KB
test_07.txt AC 515 ms 2660 KB
test_08.txt AC 20 ms 924 KB
test_09.txt AC 204 ms 1432 KB
test_10.txt AC 29 ms 1052 KB
test_11.txt AC 45 ms 1044 KB
test_12.txt AC 222 ms 1048 KB
test_13.txt AC 44 ms 1048 KB
test_14.txt AC 81 ms 1052 KB
test_15.txt AC 714 ms 2544 KB
test_16.txt AC 62 ms 1052 KB
test_17.txt AC 134 ms 1432 KB
test_18.txt AC 172 ms 1052 KB
test_19.txt AC 81 ms 1052 KB
test_20.txt AC 56 ms 1052 KB
test_21.txt AC 19 ms 924 KB
test_22.txt AC 91 ms 1048 KB
test_23.txt AC 20 ms 920 KB
test_24.txt AC 45 ms 924 KB
test_25.txt AC 211 ms 916 KB
test_26.txt AC 27 ms 924 KB
test_27.txt AC 73 ms 920 KB
test_28.txt AC 33 ms 920 KB
test_29.txt AC 201 ms 920 KB
test_30.txt AC 22 ms 924 KB
test_31.txt AC 19 ms 924 KB
test_32.txt AC 47 ms 836 KB
test_33.txt AC 187 ms 920 KB
test_34.txt AC 18 ms 920 KB
test_35.txt AC 50 ms 924 KB
test_36.txt AC 37 ms 920 KB