题目大意: 给你一个无向图, 蓝厚让你删掉一条边, 让剩下的图中的最短路 最长, maxmin系列。。
一开始想不出来解法, 就准备暴力一发试试, 也就是找到最短路之后一条条拆边, 然后不出意外的T了, 以为有什么厉害的算法, 结果赛后发现- -只因为删边的时候没加
if( ans == inf) break; 这一句, 啊啊啊居然卡这种数据我也是醉了, 然后就噩梦
#include "iostream"
#include "cstdio"
#include "cstdlib"
#include "cstring"
#include "climits"
#include "queue"
#include "cmath"
#include "map"
#include "set"
#include "stack"
#include "vector"
#include "sstream"
#include "algorithm"
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=1010;
const int maxm = 1e5 + 50;
typedef long long ll;
int dis[maxn],pnt[maxm],nxt[maxm],vis[maxn],cost[maxm];
int cnt,head[maxn],p[maxn],n;
void add(int u, int v, int w) {
pnt[cnt] = v;
nxt[cnt] = head[u];
cost[cnt] = w;
head[u] = cnt++;
}
int spfa(int id) {
memset(dis, 0x3f, sizeof dis);
dis[1] = 0;
queue<int> q;
q.push(1);
while (q.size()) {
int u = q.front();q.pop();
vis[u] = 0;
for (int i = head[u]; ~i; i = nxt[i]) {
int v = pnt[i];
if (dis[v] <= dis[u] + cost[i] || i == id) continue ;
dis[v] = dis[u] + cost[i];
p[v] = i;
if (!vis[v]) q.push(v);
vis[v] = 1;
}
}
return dis[n];
}
inline int read() {
char c = getchar();
while (!isdigit(c)) c = getchar();
int x = 0;
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
return x;
}
int main()
{
#ifdef LOCAL
freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
// freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
#endif
int T;
scanf("%d",&T);
while(T--)
{
int m,u,v,w;
scanf("%d%d",&n,&m);
memset(head,-1,sizeof head);
cnt = 0;
for(int i=1;i<=m;i++)
{
u = read();v = read(); w = read();
add(u, v, w);
add(v, u, w);
}
spfa(-1);
int now = n, ans = 0;
while (now - 1) {
int id = p[now];
ans = max(ans, spfa(id));
if (ans == inf) break;
now = pnt[id ^ 1];
}
if(ans >= inf)
cout<<"-1"<<endl;
else
cout<<ans<<endl;
}
return 0;
}