結果

問題 No.160 最短経路のうち辞書順最小
ユーザー h_nosonh_noson
提出日時 2016-04-15 11:38:02
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,280 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 63,472 KB
最終ジャッジ日時 2024-04-27 02:19:43
合計ジャッジ時間 887 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:37:13: error: ‘tie’ was not declared in this scope
   37 |             tie(u,c) = p;
      |             ^~~
main.cpp:5:1: note: ‘std::tie’ is defined in header ‘<tuple>’; did you forget to ‘#include <tuple>’?
    4 | #include <queue>
  +++ |+#include <tuple>
    5 | using namespace std;
main.cpp:48:13: error: ‘tie’ was not declared in this scope
   48 |             tie(u,c) = p;
      |             ^~~
main.cpp:48:13: note: ‘std::tie’ is defined in header ‘<tuple>’; did you forget to ‘#include <tuple>’?

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 100000000

typedef long long ll;

int main() {
    int i, n, m, s, g;
    priority_queue<int,vector<int>,greater<int>> q;
    vector<pair<int,int>> e[200];
    int d[200];
    cin >> n >> m >> s >> g;
    rep (i,m) {
        int a, b, c;
        cin >> a >> b >> c;
        e[a].push_back(make_pair(b,c));
        e[b].push_back(make_pair(a,c));
    }
    rep (i,n)
        sort(e[i].begin(),e[i].end());
    q.push(g);
    fill(d,d+n,INF);
    d[g] = 0;
    while (!q.empty()) {
        int v = q.top();
        q.pop();
        for (auto p : e[v]) {
            int u, c;
            tie(u,c) = p;
            if (d[u] > d[v] + c) {
                d[u] = d[v] + c;
                q.push(u);
            }
        }
    }
    int v = s;
    while (v != g) {
        for (auto p : e[v]) {
            int u, c;
            tie(u,c) = p;
            if (d[v] - d[u] == c) {
                cout << v << " ";
                v = u;
                break;
            }
        }
    }
    cout << g << endl;
    return 0;
}
0