結果

問題 No.416 旅行会社
ユーザー はまやんはまやん
提出日時 2016-08-29 14:07:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 396 ms / 4,000 ms
コード長 976 bytes
コンパイル時間 1,858 ms
コンパイル使用メモリ 178,900 KB
実行使用メモリ 28,532 KB
最終ジャッジ日時 2024-12-14 20:12:49
合計ジャッジ時間 6,401 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)




#define INF INT_MAX/2
int N, M, Q;
map<int, int> E[101010];
int ans[101010];
bool done[101010];
//-----------------------------------------------------------------
int main() {
	cin >> N >> M >> Q;
	rep(i, 0, M) {
		int A, B;
		scanf("%d %d", &A, &B);
		E[A][B] = INF;
		E[B][A] = INF;
	}

	rep(i, 0, Q) {
		int C, D;
		scanf("%d %d", &C, &D);
		E[C][D] = i + 1;
		E[D][C] = i + 1;
	}

	priority_queue<pair<int, int> > que;
	ans[1] = INF;
	que.push(make_pair(INF, 1));
	while (!que.empty()) {
		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 cc = p.second;
			if (ans[j] < min(ans[i], cc)) {
				ans[j] = min(ans[i], cc);
				que.push(make_pair(ans[j], j));
			}
		}
	}

	rep(i, 2, N+1) {
		if (ans[i] == INF)
			printf("-1\n");
		else
			printf("%d\n", ans[i]);
	}
}
0