結果

問題 No.416 旅行会社
ユーザー hipokabahipokaba
提出日時 2016-09-12 03:02:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 671 ms / 4,000 ms
コード長 1,029 bytes
コンパイル時間 1,622 ms
コンパイル使用メモリ 82,804 KB
実行使用メモリ 25,300 KB
最終ジャッジ日時 2023-08-21 10:04:00
合計ジャッジ時間 8,594 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 297 ms
15,448 KB
testcase_01 AC 3 ms
5,716 KB
testcase_02 AC 4 ms
5,708 KB
testcase_03 AC 3 ms
5,756 KB
testcase_04 AC 3 ms
5,760 KB
testcase_05 AC 3 ms
5,764 KB
testcase_06 AC 3 ms
5,820 KB
testcase_07 AC 5 ms
6,036 KB
testcase_08 AC 10 ms
6,168 KB
testcase_09 AC 37 ms
6,988 KB
testcase_10 AC 333 ms
15,656 KB
testcase_11 AC 327 ms
15,564 KB
testcase_12 AC 325 ms
15,456 KB
testcase_13 AC 296 ms
15,516 KB
testcase_14 AC 670 ms
25,272 KB
testcase_15 AC 665 ms
25,300 KB
testcase_16 AC 671 ms
24,972 KB
testcase_17 AC 670 ms
25,240 KB
testcase_18 AC 667 ms
25,232 KB
testcase_19 AC 478 ms
20,716 KB
testcase_20 AC 477 ms
20,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <map>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

struct E{
	int t, c;
};

int n, m, q;
map<P, int> k;
vector<E> g[100000];
int d[100000];

void make_graph(){
	for(auto& v: k){
		auto& p = v.first;
		int a = p.first - 1, b = p.second - 1;
		g[a].push_back({b, v.second});
		g[b].push_back({a, v.second});
	}
}

void dijkstra(){
	priority_queue<P> q;
	d[0] = m + 1;
	q.push(P(m + 1, 0));
	while(!q.empty()){
		P v = q.top();
		q.pop();
		if(d[v.second] > v.first){
			continue;
		}
		for(auto& e: g[v.second]){
			if(d[e.t] < min(v.first, e.c)){
				d[e.t] = min(v.first, e.c);
				q.push(P(d[e.t], e.t));
			}
		}
	}
}

int main(){
	cin >> n >> m >> q;
	rep(i, m){
		int a, b;
		cin >> a >> b;
		k[P(a, b)] = m + 1;
	}
	rep(i, q){
		int c, d;
		cin >> c >> d;
		k[P(c, d)] = i + 1;
	}

	make_graph();

	dijkstra();

	rep(i, n - 1){
		int k = d[i + 1];
		cout << (k != m + 1 ? k : -1) << endl;
	}
	return 0;
}
0