結果

問題 No.1 道のショートカット
コンテスト
ユーザー goodbaton
提出日時 2014-11-16 14:12:14
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,476 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 834 ms
コンパイル使用メモリ 100,408 KB
実行使用メモリ 107,720 KB
最終ジャッジ日時 2026-04-03 01:14:46
合計ジャッジ時間 1,501 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

struct TOWN{
    vector<int> T,Y,M;
    int way;
    TOWN(){
        way=0;
    }
} town[51];

int main(){
    int N,C,V,info[1500][4],nextcost,nextm,nexttown;
    priority_queue<pair<int,pair<int,int>>> pq;
    pair<int,pair<int,int>> now;
    
    scanf("%d%d%d",&N,&C,&V);
    
    for(int i=0;i<4;i++)
        for(int j=0;j<V;j++)
            scanf("%d",&info[j][i]);
    
    for(int i=0;i<V;i++){
        town[info[i][0]].T.push_back(info[i][1]);
        town[info[i][0]].Y.push_back(info[i][2]);
        town[info[i][0]].M.push_back(-1*info[i][3]);
        town[info[i][0]].way++;
    }
    
    pq.push(make_pair(0,make_pair(0,1)));
    
    while(!pq.empty()){
        now = pq.top();
        pq.pop();
        
        if(now.second.second==N){
            printf("%d",-1*now.first);
            return 0;
        }
        
        for(int i=0;i<town[now.second.second].way;i++){
            nextm = town[now.second.second].M[i]+now.first;
            nextcost = town[now.second.second].Y[i]+now.second.first;
            nexttown = town[now.second.second].T[i];
            if(nextcost<=C)
                pq.push(make_pair(nextm,make_pair(nextcost,nexttown)));
        }
    }
    
    puts("-1");
    return 0;
}
0