結果
問題 |
No.416 旅行会社
|
ユーザー |
![]() |
提出日時 | 2016-08-27 11:00:16 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 494 ms / 4,000 ms |
コード長 | 798 bytes |
コンパイル時間 | 1,599 ms |
コンパイル使用メモリ | 171,484 KB |
実行使用メモリ | 161,536 KB |
最終ジャッジ日時 | 2024-12-14 20:03:00 |
合計ジャッジ時間 | 7,095 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:10:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | scanf("%d %d %d", &N, &M, &Q); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:13:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 13 | scanf("%d %d", &A, &B); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int N, M, Q; map< int, int > g[100000]; scanf("%d %d %d", &N, &M, &Q); for(int i = 0; i < M + Q; i++) { int A, B; scanf("%d %d", &A, &B); --A, --B; g[A][B] = g[B][A] = i < M ? Q : i - M; } vector< queue< int > > que(Q + 1); vector< int > v(N, -1); v[0] = Q; que[Q].push(0); for(int i = Q; i >= 0; i--) { while(!que[i].empty()) { int curr = que[i].front(); que[i].pop(); if(i < v[curr]) continue; for(auto& e : g[curr]) { int cost = min(v[curr], e.second); if(v[e.first] < cost) { v[e.first] = cost; que[cost].push(e.first); } } } } for(int i = 1; i < N; i++) { printf("%d\n", v[i] == Q ? -1 : v[i] + 1); } }