P1186 玛丽卡
发布日期:2021-05-07 09:41:00 浏览次数:20 分类:精选文章

本文共 1906 字,大约阅读时间需要 6 分钟。

题目

思路

其实这题原来不hack的时候可以dij+堆优化/spfaAC的,但是后来加了3个完全图数据,然后就悲剧了,其实有很多方法可以乱搞AC,比如说该题思路应该是枚举一开始最短路上的每条边然后对删除该边的情况跑spfa最后取最大值的,但是……嘿嘿嘿,我们可以枚举少一点,卡过时限,也可以用随机数枚举,按从小到大的方式枚举+枚举少一点(以上方法只使用了第一种卡时间,其他方式TLE概不负责),但是黑心良心的作者只给出能过原来数据的题解,剩下的……

· 革命尚未成功,同志们还需努力
嘿嘿嘿
code:

#include
#include
#include
using namespace std;int b[10011],last[10011],e=1,first[10011];struct f{ int to,r; int w; int net; bool cut;} a[1100001];bool book[10011];struct f2{ int x,y;} p;void read(int& x){ x=0; int f=1; char ch=getchar(); while (!isdigit(ch)) (ch=='-')&&(f=-1),ch=getchar(); while (isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); x*=f; return; }bool operator <(const f2 &x,const f2 &y){ return x.x>y.x;}priority_queue
c;void jto(int x,int y,int z){ a[e].to=y; a[e].r=x; a[e].w=z; a[e].net=first[x]; first[x]=e; e++;}int n,m,q;vector
o;void f(){ for (int i=1;i<=n;i++) { b[i]=1000000010; book[i]=0; } b[q]=0; p.x=0,p.y=q; c.push(p); while (c.size()) { int u=c.top().y; c.pop(); if (book[u]) continue; book[u]=1; for (int i=first[u];i;i=a[i].net) { if (b[a[i].to]>b[u]+a[i].w) { b[a[i].to]=a[i].w+b[u]; last[a[i].to]=i; p.x=b[a[i].to]; p.y=a[i].to; c.push(p); } } } int y=1; while (y!=q) { o.push_back(last[y]); y=a[last[y]].r; } return;}int check(){ for (int i=1;i<=n;i++) { b[i]=1000000010; book[i]=0; } b[q]=0; p.x=0,p.y=q; c.push(p); while (c.size()) { int u=c.top().y; c.pop(); if (book[u]) continue; book[u]=1; for (int i=first[u];i;i=a[i].net) { if (a[i].cut==1) continue; if (b[a[i].to]>b[u]+a[i].w) { b[a[i].to]=a[i].w+b[u]; p.x=b[a[i].to]; p.y=a[i].to; c.push(p); } } } return b[1];}int main(){ read(n),read(m); q=n; int x,y,z,ans=-1; for (int i=1;i<=m;i++) { read(x),read(y),read(z); if (x==y) continue; jto(x,y,z); jto(y,x,z); } f(); for (int i=0;i
上一篇:P5764 [CQOI2005]新年好
下一篇:P1462 通往奥格瑞玛的道路

发表评论

最新留言

很好
[***.229.124.182]2025年04月18日 02时46分42秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章