結果

問題 No.1868 Teleporting Cyanmond
ユーザー Kome_soudouKome_soudou
提出日時 2022-03-12 19:21:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 616 ms / 2,000 ms
コード長 752 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 176,548 KB
実行使用メモリ 9,056 KB
最終ジャッジ日時 2023-10-17 04:40:27
合計ジャッジ時間 6,886 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 37 ms
8,264 KB
testcase_04 AC 28 ms
6,944 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 8 ms
4,348 KB
testcase_07 AC 20 ms
5,720 KB
testcase_08 AC 13 ms
4,832 KB
testcase_09 AC 17 ms
5,464 KB
testcase_10 AC 35 ms
7,736 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 10 ms
4,568 KB
testcase_13 AC 43 ms
5,892 KB
testcase_14 AC 148 ms
8,528 KB
testcase_15 AC 72 ms
6,992 KB
testcase_16 AC 7 ms
4,348 KB
testcase_17 AC 14 ms
4,348 KB
testcase_18 AC 616 ms
9,056 KB
testcase_19 AC 609 ms
9,056 KB
testcase_20 AC 599 ms
9,056 KB
testcase_21 AC 601 ms
9,056 KB
testcase_22 AC 589 ms
9,056 KB
testcase_23 AC 58 ms
9,056 KB
testcase_24 AC 55 ms
9,056 KB
testcase_25 AC 60 ms
9,056 KB
testcase_26 AC 53 ms
9,056 KB
testcase_27 AC 57 ms
9,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct Edge
{
	int to; // 辺の行先
	int weight; // 辺の重み
	Edge(int t, int w) : to(t), weight(w){} 
};
using Graph = vector<vector<Edge>>;

int main()
{
	int N;
	cin >> N;
	int R;
	Graph G(N);
	for(int i = 0; i < N - 1; i++)
	{
		cin >> R;
		R--;
		G[i].push_back(Edge(R, 1));
	}
	for(int i = 0; i < N - 1; i++) G[i + 1].push_back(Edge(i, 0));
	
	int inf = 100000001;
	deque<int> dq;
	dq.push_back(0);
	vector<int> dist(N, inf);
	dist[0] = 0;
	while(!dq.empty())
	{
		int p = dq.front();
		dq.pop_front();
		
		for(Edge e : G[p])
		{
			if(dist[p] + e.weight < dist[e.to])
			{
				dist[e.to] = dist[p] + e.weight;
				dq.push_back(e.to);
			}
		}
	}
	
	cout << dist[N - 1] << endl;
	return 0;
}
0