結果

問題 No.416 旅行会社
ユーザー femtofemto
提出日時 2016-08-26 23:54:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 595 ms / 4,000 ms
コード長 1,478 bytes
コンパイル時間 1,101 ms
コンパイル使用メモリ 103,844 KB
実行使用メモリ 30,816 KB
最終ジャッジ日時 2023-08-21 09:45:44
合計ジャッジ時間 8,001 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 223 ms
17,080 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 7 ms
4,376 KB
testcase_09 AC 28 ms
4,932 KB
testcase_10 AC 257 ms
16,988 KB
testcase_11 AC 258 ms
16,980 KB
testcase_12 AC 262 ms
17,072 KB
testcase_13 AC 222 ms
17,000 KB
testcase_14 AC 595 ms
30,768 KB
testcase_15 AC 593 ms
30,812 KB
testcase_16 AC 543 ms
29,800 KB
testcase_17 AC 571 ms
30,764 KB
testcase_18 AC 590 ms
30,816 KB
testcase_19 AC 416 ms
24,536 KB
testcase_20 AC 422 ms
24,336 KB
権限があれば一括ダウンロードができます

ソースコード

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 if(d[i] == -1) {
			cout << 0 << endl;
		}
		else {
			cout << d[i] << endl;
		}
	}
}
0