标签:php ace man selected include pac comm ext sel
http://acm.hdu.edu.cn/showproblem.php?pid=4738
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4415 Accepted Submission(s):
1386
#include<cstdio> #include<cstring> #include<algorithm> #define N 1001 using namespace std; int tot,front[N],to[N*N*2],nxt[N*N*2],val[N*N*2]; int dfn[N],low[N],id,ans; bool v[N],ok; int n,m; void add(int u,int v,int w) { to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; val[tot]=w; to[++tot]=u; nxt[tot]=front[v]; front[v]=tot; val[tot]=w; } void tarjer(int u,int pre) { dfn[u]=low[u]=++id; for(int i=front[u];i;i=nxt[i]) { if(i==(pre^1)) continue; if(!dfn[to[i]]) { tarjer(to[i],i); low[u]=min(low[u],low[to[i]]); if(low[to[i]]>low[u]) ans=min(ans,val[i]); } else low[u]=min(low[u],dfn[to[i]]); } } void pre() { memset(low,0,sizeof(low)); memset(dfn,0,sizeof(dfn)); memset(front,0,sizeof(front)); memset(v,0,sizeof(v)); tot=1; id=0; ans=0x7fffffff; ok=false; } int main() { int u,v,w; while(scanf("%d%d",&n,&m)!=EOF) { if(!n) return 0; pre(); while(m--) { scanf("%d%d%d",&u,&v,&w); add(u,v,w); } for(int i=1;i<=n;i++) if(!dfn[i]) { if(i!=1) { printf("0\n"); ok=true; break; } tarjer(1,0); } if(ok) continue; if(ans==0x7fffffff) ans=-1; else if(ans==0) ans=1; printf("%d\n",ans); } }
标签:php ace man selected include pac comm ext sel
原文地址:http://www.cnblogs.com/TheRoadToTheGold/p/6920047.html