Submission #1759010


Source Code Expand

#include<functional>
#include<queue>
#include<vector>

struct Graph{
    Graph(int n) :E(n), d(n) {}
    using P = std::pair<int, int>;
    std::vector<std::vector<P>>E;
    std::vector<int>d;
    void addEdge(int a, int b, int c) { E[a].emplace_back(b, c); }
    void dijkstra(int s) {
        std::priority_queue<P, std::vector<P>, std::greater<>>Q;
        fill(d.begin(), d.end(), 1 << 30);
        Q.push({ d[s] = 0,s });
        while (!Q.empty()) {
            P e = Q.top(); Q.pop();
            if (e.first > d[e.second]) continue;
            for (P& a : E[e.second]) {
                int x = a.first, y = a.second + e.first;
                if (y < d[x]) d[x] = y, Q.push({ y,x });
            }
        }
    }
    int getCost(int n) { return d[n]; }
};

#include<iostream>
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    Graph G(n);
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        G.addEdge(--a, --b, c), G.addEdge(b, a, c);
    }
    int x = 1 << 30;
    for (int i = 0; i < n; ++i) {
        G.dijkstra(i);
        x = min(x, *max_element(G.d.begin(), G.d.end()));
    }
    cout << x << endl;
}

Submission Info

Submission Time
Task D - バスと避けられない運命
User moeruAI
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1222 Byte
Status CE

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:41:55: error: ‘max_element’ was not declared in this scope
         x = min(x, *max_element(G.d.begin(), G.d.end()));
                                                       ^