题意:曹操的船之间有一些桥连接,现在周瑜想把这些连接的船分成两部分,不过他只能炸毁一座桥,并且每座桥上有士兵看守,问,他最少需要排多少士兵去炸桥如果不能做到,输出‘-1’
注意:此题有好几个坑,第一个输入桥守卫是0的话也得排一个士兵
如果一开始桥就是不连通的就不用派士兵了,直接输出 0
**************************************************************
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int MAXN = 1e3+;
const int oo = 1e9; struct Edge{int v, used, val, next;}e[MAXN*MAXN*];
int Head[MAXN], cnt;
void AddEdge(int u, int v, int val)
{
if(val == )val = ;
e[cnt].v = v;
e[cnt].used = false;
e[cnt].val = val;
e[cnt].next = Head[u];
Head[u] = cnt++;
} int low[MAXN], dfn[MAXN], Index;
int Min; void InIt(int N)
{
cnt = Index = ;
Min = oo;
for(int i=; i<=N; i++)
{
Head[i] = -;
dfn[i] = ;
}
}
void Tarjan(int u)
{
dfn[u] = low[u] = ++Index; for(int j=Head[u]; j!=-; j=e[j].next)
{
if( e[j].used == false )
{
int v = e[j].v; e[j].used = e[j^].used = true; if( !dfn[v] )
{
Tarjan(v);
low[u] = min(low[u], low[v]); if(low[v] > dfn[u])
Min = min(Min, e[j].val);
}
else
low[u] = min(low[u], dfn[v]);
}
}
} int main()
{
int N, M; while(scanf("%d%d", &N, &M), N+M)
{
int u, v, val; InIt(N); while(M--)
{
scanf("%d%d%d", &u, &v, &val);
AddEdge(u, v, val);
AddEdge(v, u, val);
} Tarjan(); for(int i=; i<=N; i++)
{
if(dfn[i] == )
Min = ;
} if(Min == oo)
printf("-1\n");
else
printf("%d\n", Min);
} return ; }