提出 #6351877


ソースコード 拡げる

#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<LL, LL> P;
struct edge { LL to, cost; };

const LL inf = 1123456789012;
std::vector<std::vector<LL>>dist;
std::vector<std::vector<edge>>G;

void dijkstra(LL s)
{
	std::priority_queue<P, std::vector<P>, std::greater<P>>que;
	dist[s][0] = 0;
	que.push(P(0, s));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		LL c = p.first, v = p.second;
		if (dist[v][c % 3] < c) continue;
		rep(i, G[v].size())
		{
			edge e = G[v][i];
			if (dist[e.to][(c + 1) % 3] > dist[v][c % 3] + e.cost)
			{
				dist[e.to][(c + 1) % 3] = dist[v][c % 3] + e.cost;
				que.push(P(c + 1, e.to));
			}
		}
	}
}

int main()
{
	LL N, M, S, T;
	in >> N >> M;
	std::vector<LL>u(M), v(M);
	rep(i, M) in >> u[i] >> v[i];
	in >> S >> T;

	dist.resize(N + 1, std::vector<LL>(3, inf));
	G.resize(N + 1);
	rep(i, M) G[u[i]].push_back({ v[i],1 });
	dijkstra(S);

	out << (dist[T][0] != inf ? dist[T][0] / 3 : -1) << std::endl;
}

提出情報

提出日時
問題 E - Hopscotch Addict
ユーザ babcs2035
言語 C++14 (GCC 5.4.1)
得点 500
コード長 1096 Byte
結果 AC
実行時間 104 ms
メモリ 12800 KiB

ジャッジ結果

セット名 All Sample
得点 / 配点 500 / 500 0 / 0
結果
AC × 23
AC × 4
セット名 テストケース
All cycle_01, cycle_02, cycle_03, killer_01, killer_02, killer_03, killer_04, long_01, long_02, random_dense_01, random_dense_02, random_max_01, random_max_02, random_max_03, random_max_04, random_max_05, random_max_06, sample_01, sample_02, sample_03, sample_04, tournament_01, tournament_02
Sample sample_01, sample_02, sample_03, sample_04
ケース名 結果 実行時間 メモリ
cycle_01 AC 72 ms 12800 KiB
cycle_02 AC 71 ms 12800 KiB
cycle_03 AC 71 ms 12800 KiB
killer_01 AC 45 ms 4096 KiB
killer_02 AC 44 ms 3968 KiB
killer_03 AC 72 ms 12156 KiB
killer_04 AC 65 ms 9588 KiB
long_01 AC 57 ms 5248 KiB
long_02 AC 71 ms 12800 KiB
random_dense_01 AC 21 ms 2176 KiB
random_dense_02 AC 40 ms 3584 KiB
random_max_01 AC 88 ms 10624 KiB
random_max_02 AC 86 ms 10880 KiB
random_max_03 AC 93 ms 9596 KiB
random_max_04 AC 90 ms 10240 KiB
random_max_05 AC 68 ms 9344 KiB
random_max_06 AC 104 ms 12544 KiB
sample_01 AC 1 ms 256 KiB
sample_02 AC 1 ms 256 KiB
sample_03 AC 1 ms 256 KiB
sample_04 AC 1 ms 256 KiB
tournament_01 AC 44 ms 4096 KiB
tournament_02 AC 44 ms 4096 KiB