結果

問題 No.1 道のショートカット
ユーザー finefine
提出日時 2016-03-29 23:12:28
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,877 bytes
コンパイル時間 1,274 ms
コンパイル使用メモリ 155,208 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-22 12:41:27
合計ジャッジ時間 7,953 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct node {
    int at;
    int cost; 
    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 = 10000000;

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();
        minc[x.at] = min(x.cost, minc[x.at]);
        for(Edge_it i = graph[x.at].begin(), e = graph[x.at].end(); i != e; ++i) {
            if (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