2292: 【POJ Challenge 】永远挑战

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 513  Solved: 201
[Submit][Status]

Description

lqp18_31和1tthinking经常出题来虐ftiasch。有一天, lqp18_31搞了一个有向图,每条边的长度都是1。 他想让ftiasch求出点1到点 N 的最短路。"水题啊。", ftiasch这么说道。

所以1tthinking把某些边的长度增加了1(也就是说,每条边的长度不是1就是2)。现在,可怜的ftiasch要向你求助了。

Input

第1行,两个整数 N (1 ≤ N ≤ 105) 和 M (1 ≤ M ≤ 106), 点和边的数量。

第2到 M + 1行: 三个整数 Ui, Vi, Wi (1 ≤ Wi ≤ 2), 从点 Ui 到 Vi 长度为 Wi 的边。

Output

一个整数,表示点1到点N的最短路。数据保证至少存在一条路径。

Sample Input

3 3
1 2 1
2 3 1
1 3 2

Sample Output

2

HINT

Source

题解:

为何出spfa裸题。。。

代码:

 #include<cstdio>

 #include<cstdlib>

 #include<cmath>

 #include<cstring>

 #include<algorithm>

 #include<iostream>

 #include<vector>

 #include<map>

 #include<set>

 #include<queue>

 #include<string>

 #define inf 1000000000

 #define maxn 100000+1000

 #define maxm 1000000+1000

 #define eps 1e-10

 #define ll long long

 #define pa pair<int,int>

 #define for0(i,n) for(int i=0;i<=(n);i++)

 #define for1(i,n) for(int i=1;i<=(n);i++)

 #define for2(i,x,y) for(int i=(x);i<=(y);i++)

 #define for3(i,x,y) for(int i=(x);i>=(y);i--)

 #define mod 1000000007

 using namespace std;

 inline int read()

 {

     int x=,f=;char ch=getchar();

     while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}

     while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}

     return x*f;

 }
struct edge{int go,next,w;}e[*maxm]; int n,m,k,s,t,tot,q[maxn],d[maxn],head[maxn]; bool v[maxn]; void insert(int x,int y,int z) { e[++tot].go=y;e[tot].w=z;e[tot].next=head[x];head[x]=tot; } void spfa() { for(int i=;i<=n;++i) d[i]=inf; memset(v,,sizeof(v)); int l=,r=,x,y;q[]=s;d[s]=; while(l!=r) { x=q[++l];if(l==maxn)l=;v[x]=; for(int i=head[x];i;i=e[i].next) if(d[x]+e[i].w<d[y=e[i].go]) { d[y]=d[x]+e[i].w; if(!v[y]){v[y]=;q[++r]=y;if(r==maxn)r=;} } } } int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); n=read();m=read();s=;t=n;int x,y;
for1(i,m)x=read(),y=read(),insert(x,y,read());
spfa();
printf("%d\n",d[t]); return ; }

BZOJ2292: 【POJ Challenge 】永远挑战的更多相关文章

  1. bzoj2292【POJ Challenge 】永远挑战*

    bzoj2292[POJ Challenge ]永远挑战 题意: 有向图,每条边长度为1或2,求1到n最短路.点数≤100000,边数≤1000000. 题解: 有人说spfa会T,所以我用了dijk ...

  2. 2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 553  Solved: 230[Submit][ ...

  3. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  4. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  5. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  6. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  7. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  8. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  9. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

随机推荐

  1. BIND9的架构与机制笔记1

    BIND9采用的是事件驱动的机制来工作,而事件的源头则是IO,IO在linux使用的EPOLL的边缘触发模式. 本篇说的是epoll,BIND9如果创建了watcher线程(宏USE_WATCHER_ ...

  2. HDU-1241Oil Deposits

    Description GeoSurvComp地质调查公司负责探测地下石油储藏. GeoSurvComp现在在一块矩形区域探测石油,并把这个大区域分成了很多小块.他们通过专业设备,来分析每个小块中是否 ...

  3. guestmount

    guestmountFor some types of changes, you may find it easier to mount the image's file system directl ...

  4. 在Windows Azure上配置VM主备切换(1)——Linux篇

    对任何一个上线系统来说,高可用设计是不可或缺的一个环节,这样才可以确保应用可以持续.稳定的运行,而不是频繁的掉线.停机.高可用设计的核心思路很简单,就是消除一切单点故障,将单点链路或者节点升级为多点. ...

  5. Storm drpc学习

    示例代码: package com.lky.test; import org.apache.commons.logging.Log; import org.apache.commons.logging ...

  6. 知方可补不足~用xsl来修饰xml

    概念相关 XSL是可扩展样式表语言的外语缩写,是一种用于以可读格式呈现 XML(标准通用标记语言的子集)数据的语言. 起始于 XSL 万维网联盟(W3C)开始发展 XSL 的原因是:存在着对于基于 X ...

  7. lesson4:利用jmeter来压测数据库

    本文讲述了如何利用jmeter来压测数据库,事例中选取了mysql作为测试数据库,其它的数据库也是一样,只需要更换驱动程序即可. 准备工作:a.mysql数据库安装,请自行百度:b.jdbc驱动包,请 ...

  8. Java finally语句到底是在return之前还是之后执行(JVM字节码分析及内部体系结构)?

    之前看了一篇关于"Java finally语句到底是在return之前还是之后执行?"这样的博客,看到兴致处,突然博客里的一个测试用例让我产生了疑惑. 测试用例如下: public ...

  9. fetch策略

    @OneToMany(mappedBy="image",cascade=CascadeType.ALL,fetch=FetchType.EAGER) @Fetch(value=Fe ...

  10. 经常使用ARM汇编指令

    一面学习,一面总结,一面记录. 以下是整理在网上找到的一些资料,简单整理记录一下,方便以后查阅. ARM处理器的指令集能够分为跳转指令.数据处理指令.程序状态寄存器(PSR)处理指令.载入/存储指令. ...