結果

問題 No.17 2つの地点に泊まりたい
ユーザー 0w10w1
提出日時 2016-11-22 18:12:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,280 bytes
コンパイル時間 1,975 ms
コンパイル使用メモリ 188,136 KB
実行使用メモリ 4,572 KB
最終ジャッジ日時 2023-08-18 06:17:23
合計ジャッジ時間 3,586 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector< vvvi > vvvvi;
typedef vector< vvvvi > vvvvvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef vector< vvl > vvvl;
typedef vector< vvvl > vvvvl;
typedef vector< vvvvl > vvvvvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< vp > vvp;
typedef vector < string > vs;
typedef vector< vs > vvs;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< vvd > vvvd;
typedef vector< bool > vb;
typedef vector< vb > vvb;

const int INF = 0x3f3f3f3f;
const int MOD7 = ( int ) 1e9 + 7;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
    if( x > v ){
        x = v;
        return 1;
    }
    return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
    if( x < v ){
        x = v;
        return 1;
    }
    return 0;
}

typedef tuple< int, int, int, int > t4i;

int N;
vi S;
int M;
vvp E;

void init(){
    cin >> N;
    S = vi( N );
    for( int i = 0; i < N; ++i )
        cin >> S[ i ];
    cin >> M;
    E = vvp( N );
    for( int i = 0; i < M; ++i ){
        int A, B, C; cin >> A >> B >> C;
        E[ A ].emplace_back( C, B );
        E[ B ].emplace_back( C, A );
    }
}

vvvi dp;

void preprocess(){
    dp = vvvi( N + 1, vvi( N + 1, vi( N, INF ) ) );
    priority_queue< t4i, vector< t4i >, greater< t4i > > pq;
    pq.emplace( dp[ N ][ N ][ 0 ] = 0, N, N, 0 );
    while( not pq.empty() ){
        int d, f, s, u; tie( d, f, s, u ) = pq.top(); pq.pop();
        if( f < N and s < N and u == N - 1 )
            cout << d << endl, exit( 0 );
        if( d != dp[ f ][ s ][ u ] ) continue;
        for( int i = 0; i < E[ u ].size(); ++i ){
            int c, v; tie( c, v ) = E[ u ][ i ];
            upmin( dp[ f ][ s ][ v ], dp[ f ][ s ][ u ] + c );
            if( f == N and v != N - 1 )
                upmin( dp[ v ][ s ][ v ], dp[ f ][ s ][ u ] + c + S[ v ] );
            else if( s == N and f != v and v != N - 1 )
                upmin( dp[ v ][ f ][ v ], dp[ f ][ s ][ u ] + c + S[ v ] );
        }
    }
}

void solve(){

}

signed main(){
    ios::sync_with_stdio( 0 );
    init();
    preprocess();
    solve();
    return 0;
}
0