luogu2865 [USACO06NOV]路障Roadblocks

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cassert>
using namespace std;
struct Edge{
    int too, nxt, val;
}edge[200005];
struct Node{
    int idd, val;
}d[25005];//开20000都会WA!不知道为什么
int n, r, hea[5005], dis[5005], sdi[5005], cnt, k=0, uu, vv, ww;
void add_edge(int fro, int too, int val){
    edge[++cnt].nxt = hea[fro];
    edge[cnt].too = too;
    edge[cnt].val = val;
    hea[fro] = cnt;
}
bool cmp(Node x, Node y){
    return x.val>y.val;
}
void dijkstra(){
    memset(dis, 0x3f, sizeof(dis));
    memset(sdi, 0x3f, sizeof(sdi));
    dis[1] = 0;
    Node ttt;
    ttt.idd = 1;
    ttt.val = 0;
    d[++k] = ttt;
    while(k){
        Node j=d[1];assert(j.idd<=5000);//断言是调试时候的
        pop_heap(d+1, d+1+k, cmp);
        k--;
        if(j.val>sdi[j.idd])    continue;
        for(int i=hea[j.idd]; i; i=edge[i].nxt){
            int t=edge[i].too;
            int tmp=j.val+edge[i].val;
            if(dis[t]>tmp){
                swap(dis[t], tmp);
                ttt.idd = t;
                ttt.val = dis[t];
                d[++k] = ttt;
                push_heap(d+1, d+1+k, cmp);
            }
            if(dis[t]<tmp && sdi[t]>tmp){
                sdi[t] = tmp;
                ttt.idd = t;
                ttt.val = sdi[t];
                d[++k] = ttt;
                push_heap(d+1, d+1+k, cmp);
            }
        }
    }
}
int main(){
    cin>>n>>r;
    memset(hea, 0, sizeof(hea));
    for(int i=1; i<=r; i++){
        scanf("%d %d %d", &uu, &vv, &ww);
        add_edge(uu, vv, ww);
        add_edge(vv, uu, ww);
    }
    dijkstra();
    cout<<sdi[n]<<endl;
    return 0;
}
时间: 2024-10-10 02:29:24

luogu2865 [USACO06NOV]路障Roadblocks的相关文章

络谷 P2865 [USACO06NOV]路障Roadblocks

P2865 [USACO06NOV]路障Roadblocks 题目描述 Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best friends. She does not want to get to her old home too quickly, because she likes the scenery along the way. She has decided t

POJ——T 3255 Roadblocks|| COGS——T 315. [POJ3255] 地砖RoadBlocks || 洛谷—— P2865 [USACO06NOV]路障Roadblocks

http://poj.org/problem?id=3255 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15680   Accepted: 5510 Description Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best friends. She does not want to get

[USACO06NOV] Roadblocks

https://www.luogu.org/problem/show?pid=2865 题目描述 Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best friends. She does not want to get to her old home too quickly, because she likes the scenery along the way. She

poj3255 Roadblocks

Roadblocks Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13594   Accepted: 4783 Description Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best friends. She does not want to get to her old home too

bzoj1726 [Usaco2006 Nov]Roadblocks第二短路

1726: [Usaco2006 Nov]Roadblocks第二短路 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 826  Solved: 394[Submit][Status] Description 贝茜把家搬到了一个小农场,但她常常回到FJ的农场去拜访她的朋友.贝茜很喜欢路边的风景,不想那么快地结束她的旅途,于是她每次回农场,都会选择第二短的路径,而不象我们所习惯的那样,选择最短路. 贝茜所在的乡村有R(1<=R<=100,000)条双向

POJ3255 Roadblocks 【次短路】

Roadblocks Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7760   Accepted: 2848 Description Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best friends. She does not want to get to her old home too q

POJ 3255 Roadblocks

Roadblocks Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 325564-bit integer IO format: %lld      Java class name: Main Bessie has moved to a small farm and sometimes enjoys returning to visit one of her bes

poj3255 Roadblocks 次短路

Roadblocks Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10098   Accepted: 3620 Description Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best friends. She does not want to get to her old home too

洛谷 P2866 [USACO06NOV]糟糕的一天Bad Hair Day

P2866 [USACO06NOV]糟糕的一天Bad Hair DaY 题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cow