题意很好理解。

由于点是可以重复到达的,但可能每次经过路径的标志不一样,所以可以设每个点有四种状态"L”,'O','V','E'。然后按这些状态进行求最短路,当然是SPFA了。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#define LL __int64
using namespace std;
const LL inf=1ll<<58;
LL dis[1350][4];
int cnt[1350][4];
LL n1j[4];
int n,m;
int hed,tail;
int que[5350000];
bool inq[1350];
struct Edge{
int u,v,nxt;
LL c;
char t;
}edge[30000];
int tot;
int head[1350]; void addedge(int u,int v,int c,char t){
edge[tot].u=u;
edge[tot].v=v;
edge[tot].c=c;
edge[tot].t=t;
edge[tot].nxt=head[u];
head[u]=tot++;
} int isure(char c){
if(c=='L') return 0;
else if (c=='O') return 1;
else if(c=='V') return 2;
return 3;
} void spfa(){
hed=tail=0;
memset(inq,false,sizeof(inq));
inq[1]=true;
que[tail++]=1;
while(hed<tail){
int u=que[hed++]; inq[u]=false;
for(int e=head[u];e!=-1;e=edge[e].nxt){
int v=edge[e].v,nt=isure(edge[e].t);
if(dis[u][nt]+edge[e].c<=dis[v][(nt+1)%4]){
bool flag=false;
if(dis[v][(nt+1)%4]>dis[u][nt]+edge[e].c){
dis[v][(nt+1)%4]=dis[u][nt]+edge[e].c;
cnt[v][(nt+1)%4]=cnt[u][nt]+1;
flag=true;
}
else{
if(cnt[v][(nt+1)%4]<cnt[u][nt]+1){
cnt[v][(nt+1)%4]=cnt[u][nt]+1;
flag=true;
}
else continue;
}
if(flag){
if(!inq[v]){
inq[v]=true;
que[tail++]=v;
}
}
}
}
}
if(dis[n][0]==inf||cnt[n][0]==0){
printf("Binbin you disappoint Sangsang again, damn it!\n");
}
else printf("Cute Sangsang, Binbin will come with a donkey after travelling %I64d meters and finding %d LOVE strings at last.\n",dis[n][0],cnt[n][0]/4); } int main(){
int T,u,v,c; char t;
int icase=0;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
tot=0;
memset(head,-1,sizeof(head));
n1j[0]=n1j[1]=n1j[2]=n1j[3]=inf;
for(int i=0;i<m;i++){
scanf("%d %d %d %c",&u,&v,&c,&t);
if(n==1){
int f=isure(t);
n1j[f]=min(n1j[f],(LL)c);
continue;
}
addedge(u,v,c,t);
addedge(v,u,c,t);
}
printf("Case %d: ",++icase);
LL leng=0;
for(int i=0;i<4;i++){
leng+=n1j[i];
}
if(n==1){
if(leng>=inf){ printf("Binbin you disappoint Sangsang again, damn it!\n");}
else{
printf("Cute Sangsang, Binbin will come with a donkey after travelling %I64d meters and finding 1 LOVE strings at last.\n",leng);
}
continue;
} for(int i=1;i<=n;i++){
dis[i][0]=dis[i][1]=dis[i][2]=dis[i][3]=inf;
cnt[i][0]=cnt[i][1]=cnt[i][2]=cnt[i][3]=0;
}
dis[1][0]=0;
spfa();
}
return 0;
}

  

HDU 4360的更多相关文章

  1. HDU 4360 As long as Binbin loves Sangsang spfa

    题意: 给定n个点m条边的无向图 每次必须沿着LOVE走,到终点时必须是完整的LOVE,且至少走出一个LOVE, 问这样情况下最短路是多少,在一样短情况下最多的LOVE个数是多少. 有自环. #inc ...

  2. 8-12-COMPETITION

    链接:最短路 A.HDU 2544    最短路 算是最基础的题目了吧.............我采用的是Dijkstra算法....... 代码: #include <iostream> ...

  3. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  5. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  6. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  8. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  9. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

随机推荐

  1. Java根据年度将数据分组

    现在有这么一组数据 code                   name                year 45615654           x1                      ...

  2. JavaScript正则表达式(一)-常用方法

    公司之前有个胖女孩说你竟然会正则? 其实正则没那么难:今天我们说说他常用的几个API. 在讲方法之前, 我们先对正则表达式做一个基本的了解: 1.正则表达式定义使用单个字符串来描述.匹配一系列符合某个 ...

  3. Java高质量20问

    问题一:在多线程环境中使用HashMap会有什么问题?在什么情况下使用get()方法会产生无限循环? HashMap本身没有什么问题,有没有问题取决于你是如何使用它的.比如,你在一个线程里初始化了一个 ...

  4. [ SCOI 2008 ] 着色方案

    \(\\\) \(Description\) 给出\(K\)种颜料各自的个数\(C_i\),每一个颜料只够涂一个格子,求将颜料用完,涂一排格子,每个格子只能涂一次的条件下,相邻两个格子的颜色互不相同的 ...

  5. Java—break跳出语句

    在开发代码时,常常会产生这样的疑惑:break跳出语句是如何应用的呢? 使用break的场景有两种:一.switch语句中.二.循环语句. 这里就不介绍switch语句,主要说一下break在循环中的 ...

  6. nodejs全局安装路径的位置

    一般nodejs安装在默认的C盘,如果不知道安装在哪里,可以打开控制面板-系统和安全-系统-高级配置中找到 所谓全局安装: 是指安装在node中node_module的根目录里,可以在电脑的任何位置调 ...

  7. RecyclerView中item无法充满的问题

    首先致谢:https://blog.csdn.net/yuanlvmao/article/details/51694211 咱们不是代码的生产者,只是代码的搬运工. 今天写了一个RecyclerVie ...

  8. c++和python如何实现主机字节序和网络字节序的相互转换

    在上一篇文章网络编程:主机字节序和网络字节序中,介绍了主机字节序和网络字节序的基本概念以及在实际的编程中,何时需要进行网络字节序和主机字节序的转换.本篇文章着重介绍使用c++和python语言,如何实 ...

  9. vim之补全1(完全个人定制版)

    关于vim的补全最初的感觉是蛋疼, 真正的蛋疼! 由于在接触linux之前曾经在windows下面学过一段时间软件开发, 那时使用的是vs2010, 现在看来虽然vs启动相当的慢, 编辑器的定制和配置 ...

  10. 【译】x86程序员手册21-6.3.5为操作系统保留的指令

    6.3.5 Some Instructions are Reserved for Operating System 为操作系统保留的一些指令 Instructions that have the po ...