結果

問題 No.416 旅行会社
ユーザー pekempey
提出日時 2016-08-27 01:21:34
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 978 bytes
コンパイル時間 1,749 ms
コンパイル使用メモリ 174,804 KB
実行使用メモリ 28,388 KB
最終ジャッジ日時 2024-11-08 18:32:03
合計ジャッジ時間 5,318 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
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