結果

問題 No.416 旅行会社
ユーザー snrnsidysnrnsidy
提出日時 2021-04-25 16:53:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 444 ms / 4,000 ms
コード長 1,378 bytes
コンパイル時間 1,368 ms
コンパイル使用メモリ 141,224 KB
実行使用メモリ 27,904 KB
最終ジャッジ日時 2023-08-21 10:44:13
合計ジャッジ時間 6,288 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
17,828 KB
testcase_01 AC 4 ms
8,252 KB
testcase_02 AC 4 ms
8,028 KB
testcase_03 AC 4 ms
8,104 KB
testcase_04 AC 4 ms
8,036 KB
testcase_05 AC 4 ms
8,080 KB
testcase_06 AC 4 ms
8,024 KB
testcase_07 AC 5 ms
8,100 KB
testcase_08 AC 6 ms
8,516 KB
testcase_09 AC 15 ms
9,284 KB
testcase_10 AC 117 ms
18,076 KB
testcase_11 AC 117 ms
17,772 KB
testcase_12 AC 116 ms
17,856 KB
testcase_13 AC 64 ms
17,852 KB
testcase_14 AC 444 ms
27,904 KB
testcase_15 AC 426 ms
27,860 KB
testcase_16 AC 414 ms
27,488 KB
testcase_17 AC 426 ms
27,836 KB
testcase_18 AC 408 ms
27,904 KB
testcase_19 AC 244 ms
22,752 KB
testcase_20 AC 250 ms
22,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <unordered_set>
#include <fstream>
#include <random>

using namespace std;
map <int, int> adj[100001];
int dist[100001];

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N, M, Q, A, B;

	cin >> N >> M >> Q;

	for (int i = 0; i < M; i++)
	{
		cin >> A >> B;
		int u = A;
		int v = B;
		adj[u][v] = 1e9;
		adj[v][u] = 1e9;
	}

	for (int i = 0; i < Q; i++)
	{
		cin >> A >> B;
		int u = A;
		int v = B;
		adj[u][v] = i + 1;
		adj[v][u] = i + 1;
	}

	
	priority_queue <pair<int, int>> pque;
	dist[1] = 1e9;
	pque.push(make_pair(dist[1], 1));
	while (!pque.empty())
	{
		int now = pque.top().second;
		pque.pop();

		for (auto it : adj[now])
		{
			int next = it.first;
			int cost = min(dist[now], it.second);
			if (dist[next] < cost)
			{
				dist[next] = cost;
				pque.push(make_pair(dist[next], next));
			}
		}
	}

	for (int i = 2; i <= N; i++)
	{
		if (dist[i] >= 1e9)
		{
			cout << -1 << '\n';
		}
		else
		{
			cout << dist[i] << '\n';
		}
	}
	return 0;
}
0