coderforce Codeforces Round #333 (Div. 1) A. The Two Routes
来源:互联网 发布:php sqllite 编辑:程序博客网 时间:2024/05/16 15:13
题意:给你一个完全图,里面的边不是火车道就是汽车道,然后任意时刻,火车和汽车都不能相遇在除了1,n的其他点
每条边的边权值都是1,然后问你最小时间使得两种车都能到达n点
解:两个Floyd算法搞定。题目中要求两个相遇的最小,则输出的应该判断二者可不可以到达,若可以到,则输出两个时间的最大,不可以就输出-1.
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define LL long longconst int inf=1<<29;const int maxm=4e2+10;int w1[maxm][maxm];int w2[maxm][maxm];int n,m;int main(){ while(scanf("%d%d",&n,&m)!=EOF) { int u,v; for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { if(i==j) { w1[i][j]=0; } else { w1[i][j]=inf; } } } for(int i=0; i<m; i++) { scanf("%d%d",&u,&v); w1[u][v]=w1[v][u]=1; } for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { if(w1[i][j]==1) { w2[i][j]=inf; } else { w2[i][j]=1; } } } for(int k=1; k<=n; k++) { for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { w1[i][j]=min(w1[i][j],w1[i][k]+w1[k][j]); } } } for(int k=1; k<=n; k++) { for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { w2[i][j]=min(w2[i][j],w2[i][k]+w2[k][j]); } } } if(w1[1][n]==inf||w2[1][n]==inf) { printf("-1\n"); } else { printf("%d\n",max(w1[1][n],w2[1][n])); } } return 0;}
0 0
- coderforce Codeforces Round #333 (Div. 1) A. The Two Routes
- CodeForces 601A The Two Routes(dijkstra最短路)——Codeforces Beta Round #333 (Div.1 Div. 2)
- Codeforces Round #333 (Div. 2) C. The Two Routes
- Codeforces Round #333 (Div. 2) C. The Two Routes
- Codeforces Round #333 (Div. 2) C. The Two Routes
- Codeforces Round #333 The Two Routes
- Codeforces #333 (Div. 1) A. The Two Routes(最短路)
- Codeforces Round #333 (Div. 2)C. The Two Routes(最短路)
- Codeforces Round #333 (Div. 2) 602C The Two Routes 最短路
- Codeforces Round #333 (Div. 2) C. The Two Routes (最短路)
- Codeforces Round #333 (Div. 2)-C The Two Routes(SPFA)
- Round 6 The Two Routes CodeForces
- 【Codeforces Round 333 (Div 2)C】【最短路】The Two Routes 完全图两种双向边的最小最大距离
- codeforces 601A The Two Routes
- Codeforces 601A The Two Routes
- CodeForces - 601A The Two Routes
- The Two Routes CodeForces
- Codeforces 601A:The Two Routes 宽搜最短路径
- c# winfrom 在panel上绘制矩形
- Android防止重复点击深入
- Mybatis resultMap空值映射问题解决
- RPM包相关介绍
- POJ1423- 数学
- coderforce Codeforces Round #333 (Div. 1) A. The Two Routes
- RecycleBin 分析
- 行为驱动开发iOS
- PHP弱类型安全
- CCBR2015青年论坛总结
- mysql分表方法-----MRG_MyISAM引擎分表法
- ScrollView反弹效果的实现
- Otter(一)初识----简介和基本架构图
- Ubuntu14.04 mysql 5.5 的中文乱码问题