/*
现场代码,枚举每条边删除
*/
#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. UVa 1328 Period

    数据范围较大,故用KMP求循环节 之后由小到大枚举长度范围,若该长度下有循环节就输出答案 还要注意输出格式.之前测试时候连着一串presentation error也是悲伤 #include<b ...

  2. CentOS 6.x安装Chromium

    在CentOS/RHEL 7出来之前继续使用Chrome怎么办?使用Chrome的开源版本:Chromium. 1.切换到root: su - 或者 sudo -i 2.下载新的软件源定义: cd / ...

  3. Sublime Text以及Package Control安装方法

    官方下载:Sublime Text 中国论坛:Sublime 论坛 Sublime Text 是一个代码编辑器,具有漂亮的用户界面和强大的功能,并且它还是一个跨平台的编辑器,同时支持Windows.L ...

  4. 【Beta】Scrum02

    Info *由于28日大家事情比较多,推迟了一天 时间:2016.11.29 21:30 时长:10min 地点:大运村1号公寓5楼楼道 类型:日常Scrum会议 NXT:2016.12.01 21: ...

  5. CentOS 6 日期 时间,时区,设置修改及时间同步

    一.时区 显示时区 date --help 获取帮助 date -R date +%z 上面两个命令都可 [root@localhost ~]# date -R; date +%z Fri, 19 O ...

  6. IOS 中的CoreImage框架(framework)

    http://www.cnblogs.com/try2do-neo/p/3601546.html coreimage framework 组成 apple 已经帮我们把image的处理分类好,来看看它 ...

  7. AngularJs:String类型和JSON相互转换

    最近一周做了一个页面,制作的过程中遇到各种问题,从中可以看出本人的js基础还不够扎实,angularjs也只是刚入门的水平,现在将制作过程中遇到的问题一一汇总,方便以后查阅. 一.String类型和J ...

  8. extjs 兼容性问题解决方案

    首先明确一点,extjs是没有所谓的兼容性的问题的.那为什么总是出现不同浏览器兼容性的问题呢?而且很多人把这作为了extjs一个缺点. 解决方法,看看写的代码是不是多了  英文逗号 , 或 中文的逗号 ...

  9. [Redis]如何通过Powershell创建Redis服务

    目前Redis在中国上线了,不过只是预览版而且不能通过Portal进行操作,不过可以通过Powershell创建,具体如下: 下载最新的Powershell SDK:http://www.window ...

  10. js确定要删除吗

    js代码 function confirm_redirect(msg, url) { if (confirm(msg)) { location.href=url; } } html <a hre ...