結果

問題 No.416 旅行会社
ユーザー あっちむいてホイ!あっちむいてホイ!
提出日時 2021-08-26 11:04:41
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 759 ms / 4,000 ms
コード長 1,153 bytes
コンパイル時間 1,558 ms
コンパイル使用メモリ 110,728 KB
実行使用メモリ 28,400 KB
最終ジャッジ日時 2023-08-21 10:46:20
合計ジャッジ時間 9,805 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 264 ms
18,108 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 7 ms
4,376 KB
testcase_09 AC 34 ms
5,212 KB
testcase_10 AC 339 ms
18,104 KB
testcase_11 AC 336 ms
18,144 KB
testcase_12 AC 334 ms
18,076 KB
testcase_13 AC 270 ms
18,004 KB
testcase_14 AC 750 ms
28,364 KB
testcase_15 AC 750 ms
28,400 KB
testcase_16 AC 750 ms
27,992 KB
testcase_17 AC 759 ms
28,396 KB
testcase_18 AC 753 ms
28,336 KB
testcase_19 AC 521 ms
23,256 KB
testcase_20 AC 531 ms
23,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
using namespace std;


int main(int argc, char const *argv[])
{
  const int INF = 1e9;
  int N,M,Q;cin >> N >> M >> Q;
  map<int,int> E[N];
  for(int i=0;i<M;++i)
  {
    int a,b;
    cin >> a >> b;
    E[--a][--b] = INF;
    E[b][a] = INF;
  }

  for(int i=0;i<Q;++i)
  {
    int c,d; cin >> c >> d;
    E[--c][--d] = i+1;
    E[d][c] = i+1;
  }
  priority_queue<pair<int,int>> que;
  vector<int> ans(N+1,0);
  ans[0] = INF;
  vector<int> done(N+1,0);
  que.push({INF,0});

  while (que.size())
  {
    auto q = que.top();que.pop();

    int c = q.first;
    int i = q.second;

    if(done[i])continue;
    done[i] = true;

    for(auto p : E[i])
    {
      int j = p.first;
      int n = p.second;
      if(ans[j] < min(ans[i],n))
      {
        ans[j] = min(ans[i],n);
        que.push({ans[j],j});
      }
    }
  }
  

  for(int i=1;i<N;++i)
  {
    if(ans[i] == INF)std::cout << -1 << std::endl;
    else std::cout << ans[i] << std::endl;
  }
}
0