/*
现场代码,枚举每条边删除
*/
#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. MySQL备份方式简介

    MySQL备份的方式主要分为两种: 文本格式备份: 命令:mysqldump 转储文件:dump file 主要内容:数据库结构及数据(create talbe /insert) 二进制备份:这类备份 ...

  2. qt 使用非系统字库

    之前的做法都是把 ttc, ttf 这些文件拷贝到系统字库里去(即拷贝到 lib/fonts 下).但是,每次添加字体,我都要把产品的文件系统都给升级一遍吗?这样系统的一致性就不大好了.所以想能不能直 ...

  3. nginx实现http反向代理+负载均衡

    原理 反向代理:反向代理(reverse proxy)方式是指以代理来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客 ...

  4. RabbitMQ安装配置

    安装RabbitMQ windows下的安装是非常简单的,我们需要准备两个东西 erlang的环境  下载windows和与之对象的操作系统位数安装包 http://www.erlang.org/do ...

  5. Unity连Photon服务器入门详解

    Photon是目前比较好用的游戏服务器.目前网上对于Photon的服务器讲解比较少,最近也对Photon做了初步的了解,做一个极其详细的入门. 首先就是得下载Photon咯 https://www.p ...

  6. pom中定义某jar包的依赖,但并不使用该jar包,那最后部署的应用中会有这个jar包么?

    关于这个问题,首先得明确这个jar包的依赖是怎么定义的,我们知道在maven的pom文件中,会有:dependencymanagement和dependency2个部分   一般我们说在depende ...

  7. Alpha版本十天冲刺——Day 9

    站立式会议 会议总结 队员 今日完成 问题 明日要做 感想 对学长说的话的感受 鲍亮 无 获取图片未解决 获取图片,发帖接口,争取完成此版本预期功能 不知不觉只剩两天时间了,这两天接连遇到发图片,获取 ...

  8. BZOJ2049: [Sdoi2008]Cave 洞穴勘测 Link-Cut-Tree 模板题

    传送门 搞了这么长时间Splay终于可以搞LCT了,等等,什么是LCT? $LCT$就是$Link-Cut-Tree$,是维护动态树的一个很高效的数据结构,每次修改和查询的均摊复杂度为$O(logN) ...

  9. nginx主备配置

    添加配置: proxy_next_upstream error timeout invalid_header http_500 http_503 http_502; upstream http.wea ...

  10. jquery的$.extend()、$.fn和$.fn.extend()

    一种是类级别的插件开发,即给jquery添加新的全局函数,相当于给jquery类本身添加方法.如$.ajax()等,这就是用$.extend()实现 jquery的全局函数就是属于jquery命名空间 ...