結果

問題 No.17 2つの地点に泊まりたい
ユーザー goodbatongoodbaton
提出日時 2015-07-28 22:02:52
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,860 bytes
コンパイル時間 755 ms
コンパイル使用メモリ 82,676 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 02:06:01
合計ジャッジ時間 1,426 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 WA -
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 1 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:31:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
main.cpp:34:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |         scanf("%d",&s[i]);
      |         ~~~~~^~~~~~~~~~~~
main.cpp:36:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |     scanf("%d",&m);
      |     ~~~~~^~~~~~~~~
main.cpp:39:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |         scanf("%d%d%d",&a,&b,&c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

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

typedef long long ll;
using namespace std;

#define mod 1000003
#define INF 1000000000
#define LLINF 2000000000000000000LL

#define SIZE 10000

int n,m,s[50],a,b,c;
bool kaku[50][51][51];
vector<pair<int,int> > way[50];
priority_queue<pair<pair<int,int>,pair<int,int> > > pq;

int main(){
    int now,cost,fir,sec;
    
    scanf("%d",&n);
    
    for(int i=1;i<=n;i++)
        scanf("%d",&s[i]);
    
    scanf("%d",&m);
    
    for(int j=0;j<m;j++){
        scanf("%d%d%d",&a,&b,&c);
        
        a++;
        b++;
        
        way[a].push_back({b,c});
        way[b].push_back({a,c});
    }
    
    pq.push({{0,1},{0,0}});
    
    while(pq.size()){
        pair<pair<int,int>,pair<int,int> > p = pq.top();
        pq.pop();
        
        cost = p.first.first;
        now = p.first.second;
        fir = p.second.first;
        sec = p.second.second;
        
        if(kaku[now][fir][sec]) continue;
        
        kaku[now][fir][sec] = true;
        
        if(now==n && fir>0 && sec>0){
            printf("%d\n",-cost);
            return 0;
        }
        
        //nowに滞在しない
        for(int i=0;i<way[now].size();i++){
            pq.push({{cost-way[now][i].second,way[now][i].first},{fir,sec}});
        }
        //nowに滞在する
        if(now==fir || sec>0 || now==1 || now==n) continue;
        
        if(fir==0)
            fir = now;
        else
            sec = now;
        
        for(int i=0;i<way[now].size();i++){
            pq.push({{cost-way[now][i].second-s[now],way[now][i].first},{fir,sec}});
        }
        
    }
    
    cerr << "error" << endl;
    
    return 0;
}
0