結果

問題 No.1 道のショートカット
ユーザー finefine
提出日時 2016-03-29 22:38:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,979 bytes
コンパイル時間 1,288 ms
コンパイル使用メモリ 155,444 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 12:41:14
合計ジャッジ時間 2,898 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct node {
    int at;
    int cost; //オーバーフローを避けるためlong longに
    int money;
    node(int at, int cost, int money) : at(at), cost(cost), money(money) {}
    bool operator>(const node &s) const {
        if (cost != s.cost) return cost > s.cost;
        if (money != s.money) return money > s.money;
        return at > s.at;
    }
};

struct Edge {
  int to;
  int t_cost;
  int m_cost;
  Edge(int to, int t_cost, int m_cost) : to(to), t_cost(t_cost), m_cost(m_cost) {}  
};

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

const int INF = 100000000;

AdjList graph;
vector<int> minc; //最短経路のコスト

void dijkstra(int n, int s, int c){ 
    minc = vector<int>(n, INF);
    priority_queue<node, vector<node>, greater<node> > pq;
    pq.push(node(s, 0, 0));
    while(!pq.empty()) {
        node x = pq.top();
        pq.pop();
        if (minc[x.at] != INF) continue;
        minc[x.at] = x.cost;
        for(Edge_it i = graph[x.at].begin(), e = graph[x.at].end(); i != e; ++i) {
            if (minc[(*i).to] != INF || x.money + (*i).m_cost > c) continue;
            pq.push(node((*i).to, x.cost + (*i).t_cost, x.money + (*i).m_cost));
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, v, c, s[1500], t[1500], y[1500], m[1500];
    cin >> n >> c >> v;
    graph = AdjList(n);
    for(int i = 0; i < v; i++) {
        cin >> s[i];
        s[i]--;
    }
    for(int i = 0; i < v; i++) {
        cin >> t[i];
        t[i]--;
    }
    for(int i = 0; i < v; i++) {
        cin >> y[i];
    }
    for(int i = 0; i < v; i++) {
        cin >> m[i];
    }
    for(int i = 0; i < v; i++) {
        graph[s[i]].push_back(Edge(t[i], m[i], y[i]));
    }
    dijkstra(n, 0, c);
    if (minc[n - 1] == INF) cout << -1 << "\n";
    else cout << minc[n - 1] << "\n";
    return 0;
    }
0