結果

問題 No.416 旅行会社
ユーザー ei1333333
提出日時 2016-08-27 10:59:40
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 797 bytes
コンパイル時間 1,874 ms
コンパイル使用メモリ 170,968 KB
実行使用メモリ 161,664 KB
最終ジャッジ日時 2024-11-08 19:02:04
合計ジャッジ時間 7,546 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
      |     ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

diff #

#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);
  }
}
0