Codeforces Round #333 (Div. 2)C. The Two Routes(最短路)
来源:互联网 发布:法兰克机器人编程 编辑:程序博客网 时间:2024/06/05 00:20
题目链接
题意:给你n个点,m边的地图,这m边是u到v之间有铁路,然后,没有给出的任意2点之间是马路。。问一个走铁路,一个走马路,从1点出发,最后2人都到达n点的时间,(他们每条路花费时间是一样的,但是二人不能同时到达某一点,一条边可以走多次)
解法:因为是完全图,必然有一个人可以直接1到n,那就在另一种类型的边上跑最短路
#define CF#ifndef CF#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#else#include<bits/stdc++.h>#endif // CFusing namespace std;#define LL long long#define pb push_back#define X first#define Y second#define cl(a,b) memset(a,b,sizeof(a))typedef pair<long long ,long long > P;const int maxn=405;const int inf=1<<29;const LL mod=1e9+7;int dis[maxn];bool mp[maxn][maxn];int n,m;bool kind;int bfs(){ queue<int> q; fill(dis,dis+n+1,inf); q.push(1); dis[1]=0; while(!q.empty()){ int u=q.front();q.pop(); for(int v=1;v<=n;v++){ if(kind&&!mp[u][v]){ if(dis[v]==inf){ dis[v]=dis[u]+1; q.push(v); } } else if(!kind&&mp[u][v]){ if(dis[v]==inf){ dis[v]=dis[u]+1; q.push(v); } } } } return dis[n];}int main(){ scanf("%d%d",&n,&m); for(int i=0;i<m;i++){ int x,y;scanf("%d%d",&x,&y); mp[x][y]=mp[y][x]=1; if(x==1&&y==n||x==n&&y==1)kind=true; } int t=bfs(); printf("%d\n",max(t,1)==inf?-1:max(t,1)); return 0;}
0 0
- Codeforces Round #333 (Div. 2)C. 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 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 (Div. 2)-C The Two Routes(SPFA)
- CodeForces 602C The Two Routes(最短路)
- Codeforces #333 (Div. 1) A. The Two Routes(最短路)
- Codeforces--333C--The Two Routes(最短路弗洛伊德)(思维)
- Codeforces 602C The Two Routes【最短路+思维】
- coderforce Codeforces Round #333 (Div. 1) A. The Two Routes
- Codeforces Round #333 The Two Routes
- CF#333(Div2) C. The Two Routes(最短路)
- Codeforces 601A The Two Routes【最短路】
- codeforces 601 A. The Two Routes (最短路d+f)
- 严蔚敏 数据结构习题6.47
- 【解决方案】Cmder v1.2 解决 “profile.ps1”和"Join-Path"方法
- CSS入门(3)-background:transparent的作用
- fastJson解析
- poj 1061/2142 扩展的欧几里得(青蛙的约会/砝码称重)
- Codeforces Round #333 (Div. 2)C. The Two Routes(最短路)
- 黑马程序员 JavaSE-09 Map
- [LeetCode261] Graph Valid Tree
- easyUI级联
- Linux下获得主机与域名-gethostbyname和gethostbyaddr
- HDU 1286.找新朋友【筛选法】【欧拉函数】【11月25】
- IE8下元素背景为透明时,hover事件失效的bug
- 2222
- 认识 Atlassian Datacenter 产品