博客又开了!
poj1797 1到n的路径最长段最小::(注意矩阵比前向星快!!!还有用STL的setRE或者T无语了)
#include<cstdio> #include<string.h> #define MAXL 1000000 #define MAXN 1100 using namespace std; int d[MAXN]; bool vis[MAXN]; int a[MAXN][MAXN]; inline int gmin(int a,int b) { if (a<b)return a; else return b; } int n; inline void form(int x) { for (int i=1;i<=n;i++) if (!vis[i]&&gmin(d[x],a[x][i])>d[i])d[i]=gmin(d[x],a[x][i]); } int main() { int t,m; scanf("%d",&t); for (int id=1;id<=t;id++){ scanf("%d%d",&n,&m); memset(a,0,sizeof(a)); for (int i=1;i<=m;i++){ int u,v,w; scanf("%d%d%d",&u,&v,&w); a[u][v]=a[v][u]=w; } for (int i=1;i<=n;i++)vis[i]=false,d[i]=0;d[1]=0x3f3f3f3f; form(1); vis[1]=true; while (!vis[n]){ int Max=0,k; for (int i=1;i<=n;i++) if (!vis[i]&&d[i]>Max){Max=d[i],k=i;} vis[k]=true; form(k); } printf("Scenario #%d:\n%d\n\n",id,d[n]); } return 0; }