結果

問題 No.416 旅行会社
ユーザー pekempeypekempey
提出日時 2016-08-27 01:21:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 978 bytes
コンパイル時間 1,503 ms
コンパイル使用メモリ 174,944 KB
実行使用メモリ 28,392 KB
最終ジャッジ日時 2024-04-26 05:44:13
合計ジャッジ時間 5,393 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
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 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |                 scanf("%d %d", &a, &b);
      |                 ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:30:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |                 scanf("%d %d", &c, &d);
      |                 ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int inf = 1e9;

template<class T1, class T2>
bool chmax(T1 &a, T2 b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int main() {
	int n, m, Q;
	cin >> n >> m >> Q;

	vector<map<int, int>> g(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		g[a][b] = inf;
		g[b][a] = inf;
	}

	for (int i = 0; i < Q; i++) {
		int c, d;
		scanf("%d %d", &c, &d);
		c--; d--;
		g[c][d] = i + 1;
		g[d][c] = i + 1;
	}

	priority_queue<pair<int, int>> q;
	q.emplace(inf, 0);

	vector<int> dist(n);
	dist[0] = inf;

	while (!q.empty()) {
		int d, curr;
		tie(d, curr) = q.top(); q.pop();

		if (d < dist[curr]) continue;

		for (auto kv : g[curr]) {
			int next = kv.first;
			int cost = kv.second;

			if (chmax(dist[next], min(dist[curr], cost))) {
				q.emplace(dist[next], next);
			}
		}
	}

	for (int i = 0; i < n; i++) {
		if (dist[i] == inf) dist[i] = -1;
		printf("%d\n", dist[i]);
	}
}
0