結果

問題 No.1 道のショートカット
ユーザー finefine
提出日時 2016-10-09 23:25:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,982 bytes
コンパイル時間 1,984 ms
コンパイル使用メモリ 176,996 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 12:49:59
合計ジャッジ時間 3,853 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 2 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 WA -
testcase_33 AC 1 ms
4,376 KB
testcase_34 WA -
testcase_35 AC 2 ms
4,380 KB
testcase_36 WA -
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 WA -
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

struct Node {
    int at;
    int time;
    int cost; 
    Node(int at, int time, int cost) : at(at), time(time), cost(cost) {}
    bool operator>(const Node &s) const {
        if (time != s.time) return time > s.time;
        if (cost != s.cost) return cost > s.cost;
        return at > s.at;
    }
};

struct Edge {
  int to;
  int time;
  int cost;
  Edge(int to, int time, int cost) : to(to), time(time), cost(cost) {}  
};

typedef vector<vector<Edge> > AdjList; //隣接リスト
typedef vector<Edge>::iterator Edge_it;

const int INF = 100000000;
const int NONE = -1;

AdjList graph;

int c;

//sは始点、mincは最短経路のコスト、Prevは最短経路をたどる際の前の頂点
void dijkstra(int s, int t, vector<int> &mint){ 
    priority_queue<Node, vector<Node>, greater<Node> > pq;
    pq.push(Node(s, 0, 0));
    while(!pq.empty()) {
        Node x = pq.top();
        pq.pop();
        if (mint[x.at] != INF || x.cost > c) continue;
        mint[x.at] = x.time;
        if (x.at == t) break;
        for(Edge_it i = graph[x.at].begin(), e = graph[x.at].end(); i != e; ++i) {
            int tmp_t = x.time + i->time;
            int tmp_c = x.cost + i->cost;
            if (mint[i->to] == INF && tmp_c <= c) {
            	pq.push(Node(i->to, tmp_t, tmp_c));
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    int v;
    cin >> n >> c >> v;
    vector<int> s(v), t(v), y(v), m(v);
    for (int i = 0; i < v; i++) cin >> s[i];
    for (int i = 0; i < v; i++) cin >> t[i];
    for (int i = 0; i < v; i++) cin >> y[i];
    for (int i = 0; i < v; i++) cin >> m[i];
    graph = AdjList(n);
    for (int i = 0; i < v; i++) {
        s[i]--;
        t[i]--;
        graph[s[i]].emplace_back(t[i], m[i], y[i]);
    }
    vector<int> mint(n, INF);
    dijkstra(0, n - 1, mint);
    cout << (mint[n - 1] == INF ? -1 : mint[n - 1]) << endl;
    return 0;
}
0