AC日记——爱情之路 codevs 2070
yh非常想念他的女朋友小y,于是他决定前往小y所在的那块大陆。
小y所在的大陆共有n个城市,m条双向路,每条路连接一个或两个城市。经过一条路ei需要耗费时间ti。此外,每条路均有一个特定标识,为’L’,’O’,’V’,’E’,中的某个字母。yh从1号城市出发,前往位于n号城市的小y所在处。
为了考验yh,小y规定,yh必须按照‘L’->’O’->’V’->’E’->’L’->’O’->’V’->’E’->.... 的顺序选择路,且所走的第一条路是’L’,最后一条路是’E’,每走完一个完整的’LOVE’算是通过一次考验
在不违背小y要求的前提下,yh想花费最少的时间到达小y的所在地,同在此时间内完成最多次考验。你能帮yh算出,他最少要花多久到达城市n,完成多少次考验呢?
第一行为两个整数n,m表示有n个城市,m条双向路。
第2行到第m+1行,每行有3个整数x,y,t和一个字符char,城市x,y之间有路,通过这条路花费的时间为t,这条路的特殊标志为 char。
输出1行,两个整数表示yh到达城市n花费的最少时间和该时间内通过的最多次考验数,如果不能到达则输出’HOLY SHIT!’
【样例输入1】
4 4
1 2 1 L
2 1 1 O
1 3 1 V
3 4 1 E
【样例输入2】
4 4
1 2 1 L
2 3 1 O
3 4 1 V
4 1 1 E
【样例输出1】
4 1
【样例输出2】
HOLY SHIT!
对于100%数据,1≤n≤1314,0≤M≤13520
思路:
spfa最短路;
每个点都拆成4个状态;
来,上代码:
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> #define maxn 20005
#define maxm 200005 using namespace std; struct sp {
int t,now;
}; struct EdgeType {
int v,w,e,type;
};
struct EdgeType edge[maxn<<]; int if_z,n,m,dis[][maxn],cnt,head[maxn],times[][maxn],tot; char Cget; bool if_[][maxn]; inline void in(int &now)
{
now=,if_z=,Cget=getchar();
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
return ;
} struct sp node(int t,int now)
{
sp pos_;
pos_.t=t,pos_.now=now;
return pos_;
} int main()
{
in(n),in(m);
int u,v,w,t;
while(m--)
{
in(u),in(v),in(w);cin>>Cget;
if(Cget=='L') t=;
if(Cget=='O') t=;
if(Cget=='V') t=;
if(Cget=='E') t=;
edge[++cnt].v=v,edge[cnt].e=head[u],edge[cnt].w=w,edge[cnt].type=t,head[u]=cnt;
edge[++cnt].v=u,edge[cnt].e=head[v],edge[cnt].w=w,edge[cnt].type=t,head[v]=cnt;
}
memset(dis,/,sizeof(dis));
dis[][]=,if_[][]=true;
queue<struct sp>que;que.push(node(,));
while(!que.empty())
{
sp pos=que.front();
if_[pos.t][pos.now]=false;que.pop();
int to=(pos.t%)+;
for(int i=head[pos.now];i;i=edge[i].e)
{
if(edge[i].type==to&&edge[i].w+dis[pos.t][pos.now]<dis[to][edge[i].v])
{
dis[to][edge[i].v]=dis[pos.t][pos.now]+edge[i].w;
// if(to==4) times[edge[i].v]=max(times[edge[i].v],times[pos.now]+1);
// if(to==4) times[to][edge[i].v]=max(times[to][edge[i].v],times[pos.t][pos.now]+1);
times[to][edge[i].v]=times[pos.t][pos.now]+;
if(!if_[to][edge[i].v])
{
que.push(node(to,edge[i].v));
if_[to][edge[i].v]=true;
}
}
else if(edge[i].type==to&&edge[i].w+dis[pos.t][pos.now]==dis[to][edge[i].v])
{
times[to][edge[i].v]=max(times[to][edge[i].v],times[pos.t][pos.now]+);
if(!if_[to][edge[i].v])
{
que.push(node(to,edge[i].v));
if_[to][edge[i].v]=true;
}
}
}
if(tot==) tot++,dis[][]=0x7ffffff;
}
if(dis[][n]>||times[][n]<) cout<<"HOLY SHIT!";
else cout<<dis[][n]<<" "<<times[][n]/;
cout<<endl;
return ;
}
AC日记——爱情之路 codevs 2070的更多相关文章
- AC日记——接龙游戏 codevs 1051
1051 接龙游戏 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 给出了N个单词,已经按长度排好了序.如果 ...
- AC日记——松江1843路 洛谷七月月赛
松江1843路 思路: 三分: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #define ...
- AC日记——地鼠游戏 codevs 1052
1052 地鼠游戏 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 王钢是一名学习成绩优异的学生,在平 ...
- AC日记——鬼谷子的钱袋 codevs 2998
2998 鬼谷子的钱袋 2006年省队选拔赛湖南 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 鬼谷子非常聪明,正 ...
- AC日记——舒适的路线 codevs 1001 (并查集+乱搞)
1001 舒适的路线 2006年 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description Z小镇是 ...
- AC日记——逃跑的拉尔夫 codevs 1026 (搜索)
1026 逃跑的拉尔夫 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 年轻的拉尔夫开玩笑地从一 ...
- AC日记——自然数和分解 codevs 2549
自然数和分解 思路: 水题: 代码: #include <bits/stdc++.h> using namespace std; ][]; int main() { cin>> ...
- AC日记——郁闷的出纳员 codevs 1286
郁闷的出纳员 思路: 设工资下限为ko,然后ko--(因为要小于工资下限): 设cur为记录工资增长,降低: 设第i个人的工资为pos: 对应的四种操作: 插入:cur-pos-ko: 增长:cur- ...
- AC日记——营业额统计 1296 codevs
1296 营业额统计 2002年 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题解 查看运行结果 题目描述 Description Tiger ...
随机推荐
- scipy应用积分操作
1.什么是scipy? SciPy是一款方便.易于使用.专为科学和工程设计的Python工具包.它包括统计,优化,整合,线性代数模块,傅里叶变换,信号和图像处理,常微分方程求解器等等. integra ...
- c# 输出不同时间的格式
C#时间/日期格式大全,C#时间/日期函数大全 有时候我们要对时间进行转换,达到不同的显示效果 默认格式为:2005-6-6 14:33:34 如果要换成成200506,06-2005,2005-6- ...
- url,href,src区别
URL(Uniform Resource Locator) 统一资源定位符是对可以从互联网上得到的资源的位置和访问方法的一种简洁的表示,是互联网上标准资源的地址.互联网上的每个文件都有一个唯一的URL ...
- Yii2.0 的安装学习
视频学习地址: 后盾网视频: http://www.houdunren.com/houdunren18_lesson_76?vid=7350 与<Yii框架>不得不说的故事—基础篇 htt ...
- k短路模板
https://acm.taifua.com/archives/jsk31445.html 链接: https://nanti.jisuanke.com/t/31445 #include <io ...
- vagrant 安装ubuntu12.04 64 bit
1 下载用于ubuntu 12.04 用于vagrant的镜像,虚拟机是virtualbox $ wget http://files.vagrantup.com/precise64.box jb@e3 ...
- HT1621控制的段式液晶驱动程序
MCU是STM8S207 /*LED 字模结构*/ typedef struct { char mChar; u8 mModal; }LED_MODAL_DEFINE; typedef struct ...
- poj1523赤裸裸的割点
这题真是没什么好说的...赤裸裸的求割点直接模板上 #include<cstdio> #include<cstring> #include<iostream> #i ...
- mysql PacketTooBigException 的处理方式
SHOW VARIABLES LIKE '%max_allowed_packet%'; set global max_allowed_packet = 2*1024*1024*1000
- git仓库删除所有提交历史记录
stackoverflow原问题地址:http://stackoverflow.com/questions/13716658/how-to-delete-all-commit-history-in-g ...