Los Valley 1613 run away __ Los Valley

Source: Internet
Author: User

Because each time can only go 2 k times stalk, so we first deal with except those points can be directly through the walk (that is, the length of 2 K-th side) can walk, realize well, a bit similar Floyd run transitive closure maintenance accessibility, and then casually run a shortest circuit data so small Floyd bubble a good, The only pit point is, I'm actually a map.

#include <cstdio>
#include <cstring>
#include <iostream>
#define MAXN 10020
Define LL long
using namespace std;
LL n,m,g[55][55],mat[70][55][55];

int main () {
	scanf ("%lld%lld", &n,&m);
	for (ll i=1;i<=n;i++) for
	(ll j=1;j<=n;j++) G[i][j]=1e17;
	
	for (LL a,b,i=1;i<=m;i++) {
		scanf ("%lld%lld", &a,&b);
		Mat[0][a][b]=1;
		g[a][b]=1;
	}
	
	for (LL-p=1;p<=64;p++) for (LL-i=1;i<=n;i++) for (LL-j=1;j<=n;j++) for (ll
	k=1;k<=n;k++)
	if (Mat[p-1][i][k]&&mat[p-1][k][j]) {
		mat[p][i][j]=1;
		g[i][j]=1;
	}
	
	for (ll k=1;k<=n;k++) {for (ll
		i=1;i<=n;i++) {for
			(ll j=1;j<=n;j++) {
				g[i][j]=min (g[i][j],g[i ][K]+G[K][J]);
	
	}} printf ("%lld", G[1][n]);
	return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.