luogu2865 [USACO06NOV]路障Roadblocks
Posted poorpool
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}
以上是关于luogu2865 [USACO06NOV]路障Roadblocks的主要内容,如果未能解决你的问题,请参考以下文章
POJ——T 3255 Roadblocks|| COGS——T 315. [POJ3255] 地砖RoadBlocks || 洛谷—— P2865 [USACO06NOV]路障Roadblocks(
luogu1879 [USACO06NOV]玉米田Corn Fields
luogu P1879 [USACO06NOV]玉米田Corn Fields 题解
ybtoj 状压DP课堂过关 例题1jzoj 1266 luogu P1879 [USACO06NOV]Corn Fields G & 玉米田 & 种植方案