/*
现场代码,枚举每条边删除
*/
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#define mx 1005 using namespace std;
struct orz
{
int d,p;
friend bool operator <(orz a,orz b) {return a.d>b.d;}
};
struct Edge{
int to;
int w;
int id;
};
priority_queue < orz > ss;
int flag,cnt,v[mx],d[mx],n,m,l;
vector<Edge> edge[mx];
bool vis[mx];
void input(){
cin>>n>>l;
int u,v,wei;
Edge test;
for(int i = ;i <= l;i++){
cin>>u>>v>>wei;
if(u == v) continue;
test.id = ++cnt;
test.to = v;
test.w = wei;
edge[u].push_back(test);
test.to = u;
edge[v].push_back(test);
}
m = ;
}
void dij(int s)
{
for(int i = ;i < mx;i++) d[i] = ;
d[s]=;
orz tmp;
tmp.d=,tmp.p=s;
ss.push(tmp);
flag++;
int x,dd;
Edge j;
while (!ss.empty())
{
tmp=ss.top();
ss.pop();
x=tmp.p,dd=tmp.d;
if (v[x]==flag) continue;
v[x]=flag;
for (int i = ;i < edge[x].size();i++){
if(vis[edge[x][i].id]) continue;
j = edge[x][i];
if (d[j.to]>dd+j.w)
{
d[j.to]=dd+j.w;
tmp.d=dd+j.w,tmp.p=j.to;
ss.push(tmp);
}
} }
}
int main(){
freopen("di.in","r",stdin);
freopen("di.out","w",stdout);
input();
int ans = ;
for(int i = ;i <= cnt;i++){
vis[i] = true;
dij();
vis[i] = false;
if(d[n] < ) ans = max(ans,d[n]);
}
cout<<ans;
return ;
}
/*
要使最短路改变,就只能删除最短路经过的边
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm> using namespace std; const int maxn=;
const int maxm=; int n,m,en,f[maxn],q[maxn],dist[maxn],edg[maxm][],z[maxn]; bool use[maxn]; struct edge
{
int e,d,id;
edge *next;
}*v[maxn],ed[maxm<<],*fe[maxn]; void add_edge(int id,int s,int e,int d)
{
en++;
ed[en].next=v[s];v[s]=ed+en;v[s]->e=e;v[s]->d=d;v[s]->id=id;
} void spfa()
{
int front=,tail=;
memset(dist,0x3f,sizeof(dist));
dist[]=;
use[]=true;
q[]=;
for (;front!=tail;)
{
int now=q[front++];
if (front==maxn) front=;
use[now]=false;
for (edge *e=v[now];e;e=e->next)
if (dist[e->e]>dist[now]+e->d)
{
dist[e->e]=dist[now]+e->d;
f[e->e]=now;fe[e->e]=e;
if (!use[e->e])
{
use[e->e]=true;
q[tail++]=e->e;
if (tail==maxn) tail=;
}
}
}
} int main()
{
freopen("di.in","r",stdin);
freopen("di.out","w",stdout); scanf("%d%d",&n,&m);
for (int a=;a<=m;a++)
scanf("%d%d%d",&edg[a][],&edg[a][],&edg[a][]);
for (int a=;a<=m;a++)
{
add_edge(a,edg[a][],edg[a][],edg[a][]);
add_edge(a,edg[a][],edg[a][],edg[a][]);
}
spfa();
int cnt=;
for (int a=n;a!=;a=f[a])
z[++cnt]=fe[a]->id;
int ans=-;
for (int a=;a<=cnt;a++)
{
en=;
memset(v,,sizeof(v));
for (int b=;b<=m;b++)
if (b!=z[a])
{
add_edge(b,edg[b][],edg[b][],edg[b][]);
add_edge(b,edg[b][],edg[b][],edg[b][]);
}
spfa();
if (dist[n]!=0x3f3f3f3f) ans=max(ans,dist[n]);
}
printf("%d\n",ans); return ;
}

清北暑假模拟day2 之的更多相关文章

  1. 清北暑假模拟day2 将

    /* 爆搜,正解弃坑 */ #include<iostream> #include<cstdio> #include<string> #include<cst ...

  2. 清北暑假模拟day2 国

    [题目描述]在世界的东边,有三瓶雪碧.--laekov黎大爷为了虐 zhx,给 zhx 出了这样一道题.黎大爷搞了一个数据结构,但是他没有告诉 zhx 这到底是什么数据结构,我们只知道这是一个数据结构 ...

  3. 清北暑假模拟day1 艳阳天

    /* 注意P有可能不是质数,不要用欧拉函数那一套,正解可以倍增,就是等比数列和的性质,注意n是否为奇数 */ #include <cstdio> #include <algorith ...

  4. 清北暑假模拟day1 生活

    /* 数字三角形,要求第K大的值,可以推知,如果得知k的范围,那么一定是在上一行可转移状态的对应范围内(反证法可以证明),这个在背包九讲里也有提及 */ #include<cstdio> ...

  5. 清北暑假模拟day1 爱

    /* 水题 */ #include<iostream> #include<cstdio> #include<string> #include<cstring& ...

  6. 清北学堂模拟赛day7 数字碰撞

    /* clj:水题别人都满分你不是你就完了,所以说水题一定要细心一点,有这么几个细节:①前导零的处理,全是零的时候要特判②换行要注意,不要多大一行,剩下就是水水的模拟了 */ #include< ...

  7. 清北学堂模拟赛d4t1 a

    分析:大模拟,没什么好说的.我在考场上犯了一个超级低级的错误:while (scanf("%s",s + 1)),导致了死循环,血的教训啊,以后要记住了. /* 1.没有发生改变, ...

  8. 清北学堂模拟赛day7 错排问题

    /* 考虑一下已经放回m本书的情况,已经有书的格子不要管他,考虑没有书的格子,不考虑错排有(n-m)!种,在逐步考虑有放回原来位置的情况,已经放出去和已经被占好的格子,不用考虑,剩下全都考虑,设t=x ...

  9. 清北学堂模拟赛day7 石子合并加强版

    /* 注意到合并三堆需要枚举两个端点,其实可以开一个数组记录合并两堆的结果,标程好像用了一个神奇的优化 */ #include<iostream> #include<cstdio&g ...

随机推荐

  1. C#的参数修饰符out,params,ref

    using System; namespace ParamsProgram { class TestParams { public static void Main(string[] args)//s ...

  2. 基本概率分布Basic Concept of Probability Distributions 7: Uniform Distribution

    PDF version PDF & CDF The probability density function of the uniform distribution is $$f(x; \al ...

  3. Untiy3D - 窗口界面1

    记录Untiy3D学习中的英语单词 一.Project窗口下的英语单词 First Day Folder : 文件夹 C# Script : C#脚本 JavaScript:JS脚本 Editor T ...

  4. Glusterfs分布式存储介绍(一)

    环境准备 1.centos6.8 系统的虚拟机(四台) 2.关闭iptables和SELinux 3.预装glusterfs软件包 yum install -y centos-release-glus ...

  5. CSS的4种引入方式及优先级

    第一:css的四种引入方式 1.行内样式 最直接最简单的一种,直接对HTML标签使用style="",例如: <p style="color:#F00; " ...

  6. mysql数据库添加索引优化查询效率

    项目中如果表中的数据过多的话,会影响查询的效率,那么我们需要想办法优化查询,通常添加索引就是我们的选择之一: 1.添加PRIMARY KEY(主键索引) mysql>ALTER TABLE `t ...

  7. wpf的毛边窗体效果 前台代码

    <Window x:Class="wpfwindowsmove.毛边窗体"        xmlns="http://schemas.microsoft.com/w ...

  8. Java数据结构——双向链表

    //================================================= // File Name : DoublyLinked_demo //------------- ...

  9. OBJ Loader Source Code

    https://github.com/ChrisJansson/ObjLoader http://www.codeproject.com/Articles/798054/SimpleScene-d-s ...

  10. 关于webpack抛出对象到全局的问题

    一般情况下,我们用webpack的时候.大多是用在单页应用上. 单是,某些情况下,我们用来做多页面的时候,有的时候,会需要在html内嵌 <script>,比如说,这个页面是服务端渲染的, ...