結果

問題 No.416 旅行会社
ユーザー ant2357ant2357
提出日時 2018-02-23 00:03:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 546 ms / 4,000 ms
コード長 1,140 bytes
コンパイル時間 5,591 ms
コンパイル使用メモリ 216,816 KB
実行使用メモリ 28,032 KB
最終ジャッジ日時 2023-08-21 10:16:56
合計ジャッジ時間 9,588 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 185 ms
17,536 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 26 ms
4,908 KB
testcase_10 AC 254 ms
17,480 KB
testcase_11 AC 246 ms
17,424 KB
testcase_12 AC 248 ms
17,464 KB
testcase_13 AC 181 ms
17,416 KB
testcase_14 AC 546 ms
28,000 KB
testcase_15 AC 540 ms
27,924 KB
testcase_16 AC 535 ms
27,636 KB
testcase_17 AC 532 ms
27,852 KB
testcase_18 AC 541 ms
28,032 KB
testcase_19 AC 409 ms
23,008 KB
testcase_20 AC 406 ms
22,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, m, q;
	cin >> n >> m >> q;

	vector<map<int, int>> g(n);
	for (int i = 0; i < m; i++) {
		ll a, b;
		cin >> a >> b;
		a--; b--;

		g[a][b] = g[b][a] = INF;
	}

	for (int i = 0; i < q; i++) {
		int c, d;
		cin >> c >> d;
		c--; d--;
		g[c][d] = g[d][c] = i + 1;
	}

	priority_queue<pair<int, int>> pq;
	vector<int> ans(n);
	ans[0] = INF;
	pq.emplace(INF, 0);

	vector<bool> used(n);
	while (!pq.empty()) {
		int c = pq.top().first;
		int i = pq.top().second;
		pq.pop();
		if (used[i]) {
			continue;
		}

		used[i] = true;
		for (auto p : g[i]) {
			int j = p.first;
			int cc = p.second;
			if (ans[j] < min(ans[i], cc)) {
				ans[j] = min(ans[i], cc);
				pq.emplace(ans[j], j);
			}
		}
	}

	for (int i = 1; i < n; i++) {
		cout << (ans[i] == INF ? -1 : ans[i]) << endl;
	}
	return 0;
}
0