結果
問題 |
No.416 旅行会社
|
ユーザー |
|
提出日時 | 2016-08-27 01:21:50 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 423 ms / 4,000 ms |
コード長 | 978 bytes |
コンパイル時間 | 1,802 ms |
コンパイル使用メモリ | 176,024 KB |
実行使用メモリ | 28,260 KB |
最終ジャッジ日時 | 2024-12-14 19:59:28 |
合計ジャッジ時間 | 6,624 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:22:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 22 | scanf("%d %d", &a, &b); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:30:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | scanf("%d %d", &c, &d); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; template<class T1, class T2> bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } int main() { int n, m, Q; cin >> n >> m >> Q; vector<map<int, int>> g(n); for (int i = 0; i < m; i++) { int a, b; scanf("%d %d", &a, &b); a--; b--; g[a][b] = inf; g[b][a] = inf; } for (int i = 0; i < Q; i++) { int c, d; scanf("%d %d", &c, &d); c--; d--; g[c][d] = i + 1; g[d][c] = i + 1; } priority_queue<pair<int, int>> q; q.emplace(inf, 0); vector<int> dist(n); dist[0] = inf; while (!q.empty()) { int d, curr; tie(d, curr) = q.top(); q.pop(); if (d < dist[curr]) continue; for (auto kv : g[curr]) { int next = kv.first; int cost = kv.second; if (chmax(dist[next], min(dist[curr], cost))) { q.emplace(dist[next], next); } } } for (int i = 1; i < n; i++) { if (dist[i] == inf) dist[i] = -1; printf("%d\n", dist[i]); } }