結果
問題 | No.416 旅行会社 |
ユーザー |
![]() |
提出日時 | 2016-09-12 03:02:04 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 708 ms / 4,000 ms |
コード長 | 1,029 bytes |
コンパイル時間 | 925 ms |
コンパイル使用メモリ | 81,632 KB |
実行使用メモリ | 25,648 KB |
最終ジャッジ日時 | 2024-12-14 20:15:42 |
合計ジャッジ時間 | 8,690 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include <iostream>#include <queue>#include <map>#include <algorithm>#define rep(i, n) for(int i = 0; i < (n); ++i)using namespace std;typedef pair<int, int> P;struct E{int t, c;};int n, m, q;map<P, int> k;vector<E> g[100000];int d[100000];void make_graph(){for(auto& v: k){auto& p = v.first;int a = p.first - 1, b = p.second - 1;g[a].push_back({b, v.second});g[b].push_back({a, v.second});}}void dijkstra(){priority_queue<P> q;d[0] = m + 1;q.push(P(m + 1, 0));while(!q.empty()){P v = q.top();q.pop();if(d[v.second] > v.first){continue;}for(auto& e: g[v.second]){if(d[e.t] < min(v.first, e.c)){d[e.t] = min(v.first, e.c);q.push(P(d[e.t], e.t));}}}}int main(){cin >> n >> m >> q;rep(i, m){int a, b;cin >> a >> b;k[P(a, b)] = m + 1;}rep(i, q){int c, d;cin >> c >> d;k[P(c, d)] = i + 1;}make_graph();dijkstra();rep(i, n - 1){int k = d[i + 1];cout << (k != m + 1 ? k : -1) << endl;}return 0;}