結果

問題 No.90 品物の並び替え
ユーザー ry0u_ydry0u_yd
提出日時 2015-09-02 02:07:36
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,472 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 77,080 KB
実行使用メモリ 4,564 KB
最終ジャッジ日時 2023-09-25 21:53:30
合計ジャッジ時間 1,624 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct edge {
    int from,to;
    int cost;

    edge(int t,int c) : to(t),cost(c) {}
    edge(int f,int t,int c) : from(f),to(t),cost(c) {}

    bool operator<(const edge &e) const {
        return cost < e.cost;
    }
};

vector<edge> G[15];
int d[15];

void dijkstra(int s,int n) {
    priority_queue<P,vector<P>,greater<P> > que;
    fill(d,d+n,INF);

    d[s] = 0;
    que.push(P(0,s));

    while(que.size()) {
        P p = que.top();
        que.pop();

        int v = p.second;
        if(d[v] < p.first) continue;

        rep(i,G[v].size()) {
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main() {
    int n,m;
    cin >> n >> m;

    rep(i,m) {
        int s,t,c;
        cin >> s >> t >> c;

        G[s].push_back(edge(t,c));
    }

    int ans = 0;
    rep(i,m) {
        dijkstra(i,n);
        rep(j,n) {
            if(d[j] == INF) continue;
            ans = max(ans,d[j]);
        }
    }

    cout << ans << endl;


    return 0;
}
0