結果

問題 No.416 旅行会社
ユーザー femtofemto
提出日時 2016-08-26 23:53:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,428 bytes
コンパイル時間 1,397 ms
コンパイル使用メモリ 107,112 KB
実行使用メモリ 31,288 KB
最終ジャッジ日時 2024-04-26 04:04:49
合計ジャッジ時間 8,063 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 226 ms
17,232 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 269 ms
17,280 KB
testcase_11 AC 246 ms
17,408 KB
testcase_12 AC 252 ms
17,408 KB
testcase_13 AC 232 ms
17,408 KB
testcase_14 AC 583 ms
31,028 KB
testcase_15 AC 596 ms
31,024 KB
testcase_16 AC 539 ms
30,004 KB
testcase_17 AC 551 ms
31,160 KB
testcase_18 AC 575 ms
31,288 KB
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
using namespace std;

typedef long long W;

const W INF = 1 << 25;

struct edge {
	int to;
	W cost;
};
typedef pair<W, int> P;
typedef vector<vector <edge > > Graph;

void dijkstra(int s, const Graph& G, vector<W>& d) {
	priority_queue<P> que;
	fill(d.begin(), d.end(), -1);
	d[s] = INF;
	que.push(P(INF, s));
	while(!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] > p.first) continue;
		for(int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if(d[e.to] < min(d[v], e.cost)) {
				d[e.to] = min(d[v], e.cost);
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

const int MAX = 100010;

int N, M, Q;

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

	map<P, int> m;
	cin >> N >> M >> Q;
	for(int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		m[P(A, B)] = INF;
	}

	for(int i = 1; i <= Q; i++) {
		int A, B;
		cin >> A >> B;
		m[P(A, B)] = i;
	}

	Graph G(N);

	for(auto val : m) {
		int A = val.first.first, B = val.first.second;
		int T = val.second;
		G[A - 1].push_back(edge{ B - 1, T });
		G[B - 1].push_back(edge{ A - 1, T });
	}

	vector<W> d(N);
	dijkstra(0, G, d);

	for(int i = 1; i < N; i++) {
		if(d[i] == INF) {
			cout << -1 << endl;
		}
		else {
			cout << d[i] << endl;
		}
	}
}
0