結果

問題 No.416 旅行会社
ユーザー ant2357ant2357
提出日時 2018-02-23 00:02:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,141 bytes
コンパイル時間 2,335 ms
コンパイル使用メモリ 213,376 KB
実行使用メモリ 27,904 KB
最終ジャッジ日時 2024-04-15 01:43:36
合計ジャッジ時間 8,749 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 182 ms
17,648 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 247 ms
17,748 KB
testcase_11 AC 244 ms
17,644 KB
testcase_12 AC 236 ms
17,676 KB
testcase_13 AC 182 ms
17,648 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

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(0, INF);

	vector<bool> used(n);
	while (!pq.empty()) {
		int i = pq.top().first;
		int c = 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(j, ans[j]);
			}
		}
	}

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