結果

問題 No.1473 おでぶなおばけさん
ユーザー Kome_soudouKome_soudou
提出日時 2022-03-23 13:34:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 1,327 bytes
コンパイル時間 2,121 ms
コンパイル使用メモリ 172,800 KB
実行使用メモリ 11,692 KB
最終ジャッジ日時 2024-04-19 19:08:35
合計ジャッジ時間 9,096 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 199 ms
11,464 KB
testcase_03 AC 136 ms
10,368 KB
testcase_04 AC 108 ms
7,728 KB
testcase_05 AC 44 ms
5,376 KB
testcase_06 AC 192 ms
10,984 KB
testcase_07 AC 172 ms
11,688 KB
testcase_08 AC 223 ms
11,692 KB
testcase_09 AC 161 ms
11,688 KB
testcase_10 AC 98 ms
7,552 KB
testcase_11 AC 101 ms
8,704 KB
testcase_12 AC 97 ms
8,192 KB
testcase_13 AC 58 ms
6,400 KB
testcase_14 AC 43 ms
5,376 KB
testcase_15 AC 83 ms
7,680 KB
testcase_16 AC 93 ms
6,912 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 AC 13 ms
5,376 KB
testcase_19 AC 83 ms
7,552 KB
testcase_20 AC 106 ms
9,536 KB
testcase_21 AC 132 ms
9,428 KB
testcase_22 AC 95 ms
10,560 KB
testcase_23 AC 77 ms
9,492 KB
testcase_24 AC 81 ms
9,400 KB
testcase_25 AC 228 ms
10,412 KB
testcase_26 AC 238 ms
10,624 KB
testcase_27 AC 69 ms
6,272 KB
testcase_28 AC 206 ms
11,564 KB
testcase_29 AC 134 ms
9,264 KB
testcase_30 AC 174 ms
10,368 KB
testcase_31 AC 141 ms
11,508 KB
testcase_32 AC 147 ms
11,096 KB
testcase_33 AC 109 ms
9,504 KB
testcase_34 AC 59 ms
6,536 KB
testcase_35 AC 64 ms
6,944 KB
testcase_36 AC 116 ms
8,304 KB
testcase_37 AC 135 ms
9,120 KB
testcase_38 AC 25 ms
5,376 KB
testcase_39 AC 98 ms
6,912 KB
testcase_40 AC 96 ms
7,040 KB
testcase_41 AC 84 ms
6,484 KB
testcase_42 AC 84 ms
6,484 KB
testcase_43 AC 102 ms
9,064 KB
testcase_44 AC 102 ms
9,320 KB
testcase_45 AC 103 ms
9,064 KB
testcase_46 AC 118 ms
9,268 KB
testcase_47 AC 142 ms
10,240 KB
testcase_48 AC 137 ms
9,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct Edge
{
	int64_t to; // 辺の行先
	int64_t weight; // 辺の重み
	Edge(int64_t t, int64_t w) : to(t), weight(w){} 
};

using Graph = vector<vector<Edge>>;

int main()
{
	int64_t N, M;
	cin >> N >> M;
	
	Graph G(N);
	int64_t S, T, D;
	for(int64_t i = 0; i < M; i++)
	{
		cin >> S >> T >> D;
		S--; T--;
		G[S].push_back(Edge(T, D));
		G[T].push_back(Edge(S, D));
	}
	
	int64_t ok = 1;
	int64_t ng = 1000000001;
	int64_t mid;
	const int64_t inf = 1000000001;
	queue<int64_t> q;
	int64_t ans;
	while(ng - ok != 1)
	{
		mid = (ng + ok) / 2;
		vector<int64_t> dist(N, inf);
		dist[0] = 0;
		q.push(0);
		while(!q.empty())
		{
			int64_t p = q.front();
			q.pop();
			
			for(Edge e : G[p])
			{
				if(e.weight < mid) continue;
				if(dist[p] + 1 < dist[e.to])
				{
					dist[e.to] = dist[p] + 1;
					q.push(e.to);
				}
			}
		}
		
		if(dist[N - 1] != inf)
		{
			ok = mid;
			ans = dist[N - 1];
		}
		else ng = mid;
	}
	
	if(ok == 1)
	{
		vector<int64_t> dist(N, inf);
		dist[0] = 0;
		q.push(0);
		while(!q.empty())
		{
			int64_t p = q.front();
			q.pop();
			
			for(Edge e : G[p])
			{
				if(dist[p] + 1 < dist[e.to])
				{
					dist[e.to] = dist[p] + 1;
					q.push(e.to);
				}
			}
		}
		
		ans = dist[N - 1];
	}
	
	cout << ok << ' ' << ans << endl;
	return 0;
}
0