結果

問題 No.17 2つの地点に泊まりたい
ユーザー nanophoto12nanophoto12
提出日時 2016-03-07 05:50:32
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,581 bytes
コンパイル時間 968 ms
コンパイル使用メモリ 84,152 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 20:13:01
合計ジャッジ時間 1,979 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
4,348 KB
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 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
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 <queue>
#include <algorithm>
#include <vector>
#include <set>
#include <iostream>
#include <numeric>
#include <tuple>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef tuple<int,int,int> tiii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define ALL(container) (container).begin(), (container).end()



struct edge{
    edge(int to_,int cost_) : to(to_), cost(cost_)
    {
    }
    int to;
    int cost;
};

int N;
int s[51];
int M;

vector<edge> g[51];

static const int INF = 10000000;


int main(){
    cin >> N;
    REP(i, N)
    {
        cin >> s[i];
    }
    cin >> M;
    REP(i, M)
    {
        int a,b,c;
        cin >> a >> b >> c;
        g[a].emplace_back(b,c);
        g[b].emplace_back(a,c);
    }
    
    int minCost = INF;
    
    REP(i, g[0].size())
    {
        auto& next = g[0][i];
        if(next.to == N-1)
        {
            continue;
        }
        REP(j, g[next.to].size())
        {
            auto & nn = g[next.to][j];
            if(nn.to == 0)
            {
                continue;
            }
            REP(k, g[nn.to].size())
            {
                auto & nnn = g[nn.to][k];
                if(nnn.to != N-1)
                {
                    continue;
                }
                auto sum = next.cost + s[next.to]
                 + nn.cost + s[nn.to]
                + nnn.cost + s[nnn.to];
                minCost=min(minCost, sum);
            }
        }
    }
    cout << minCost << endl;
    return 0;
}
0