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), 从点 UiVi 长度为 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. ACM2055_ctype.h_cctype

    #include<iostream> int main() { using namespace std; int y,count; char x; cin>>count; wh ...

  2. linux ubuntu 浏览器 字 字体 虚 解决办法

    在刚装好的ubuntu上什么都好,只是浏览器字体很虚,就连百度都虚 解决办法很简单 安装雅黑字体 修改font conf sudo vi /etc/fonts/conf.avail/69-langua ...

  3. DedeCMS源码安装

    一.源码下载地址 可以从以下网站下载DedeCMS源码进行安装,这里我下载了AB模板网的一个服装网站源码来演示DedeCMS源码的安装 http://www.adminbuy.cn/dedecms/2 ...

  4. C++中的static成员

    C++中的static 成员永远是我心中的痛,记了好多次了,但是今天在项目中依然忘记了,今天写下来,方便以后不用再去Baidu.google搜索了. 在头文件中声明静态成员 static int i; ...

  5. Python顺序与range和random

    range([start,] stop[, step]) start是开始,stop是停下,step是步长. >>> range(10) range(0, 10) >>& ...

  6. JAVA内存区域和GC机制

    目录 Java垃圾回收概况 Java内存区域 Java对象的访问方式 Java内存分配机制 Java GC机制 垃圾收集器 Java垃圾回收概况 Java GC(Garbage Collection, ...

  7. Tooltip(提示框)组件

    一.加载方式 //class加载方式 <a href="http://www.ycku.com" title="这是一个提示信息!" class=&quo ...

  8. rhel6.4 using centos source

    rhel 默认的 yum 依赖于 rhn,要注册收费才能 update,改用 centos 的源: rpm -e yum* --nodeps rpm -qa | grep yum | xargs rp ...

  9. DOM中的NodeList与HTMLCollection

    最近在看<Javascript高级程序设计>的时候,看到了这样一句话:“理解NodeList和HTMLCollection,是从整体上透彻理解DOM的关键所在.”,所以觉得应该写一篇关于N ...

  10. Search 和 Select比较 - 浅谈

    Search 语法: public IFeatureCursor Search (    IQueryFilter filter,    bool Recycling); Select 语法: pub ...