记录编号 121347 评测结果 AAAAAAAAAAAA
题目名称 [USACO Feb05] 神秘的挤奶机 最终得分 100
用户昵称 GravatarHouJikan 是否通过 通过
代码语言 C++ 运行时间 1.276 s
提交时间 2014-09-19 15:39:28 内存使用 0.18 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <iterator>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <functional>
#include <deque>
#define For(i,j,k) for(int i=(j);i<=(k);i++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x7ffffff;
//================struct declaration======================
struct adj
{
  int from,to,dist;
  bool used;
  adj(int from=0,int to=0,int dist=0):from(from),to(to),dist(dist){used=false;}
};
//================var declaration=========================
const int MAXN=210;
vector <int> G[MAXN];
vector <adj> Edge;
int n,m,k,tot=0,ans=0;
int pa[MAXN],dist[MAXN];
bool inq[MAXN];
//================function declaration====================
void spfa();
//================main code===============================
using namespace std;
int main()
{
  string ProgrammeName="secretmilking";
  string FloderName="COGS";
  freopen((ProgrammeName+".in").c_str(),"r",stdin);
  freopen((ProgrammeName+".out").c_str(),"w",stdout);
#ifdef DEBUG
  clock_t Start_Time=clock();
  system(("copy C:\\Users\\abc\\Desktop\\HouJikan\\"+FloderName+"\\standard.cpp C:\\Users\\abc\\Desktop\\HouJikan\\"+FloderName+"\\submit.txt").c_str());
#endif
  scanf("%d%d%d",&n,&m,&k);
  For(i,1,m)
  {
    int s,e,d;
    scanf("%d%d%d",&s,&e,&d);
    G[s].push_back(tot++);
    Edge.push_back(adj(s,e,d));
    G[e].push_back(tot++);
    Edge.push_back(adj(e,s,d));
  }
  For(i,1,k)
    spfa();
  printf("%d\n",ans);
#ifdef DEBUG
  clock_t End_Time=clock();
  printf("\n\nTime Used :%.6lf Ms\n",double(Start_Time-End_Time)/(-CLOCKS_PER_SEC));
#endif
  return 0;
}
//================function code===========================
void spfa()
{
   memset(inq,false,sizeof(inq));
   For(i,1,n)
     dist[i]=INF,pa[i]=i;
   dist[1]=0;
   queue <int> Q;
   Q.push(1);
   while (!Q.empty())
   {
     int now=Q.front();Q.pop();
     int siz=G[now].size()-1;
     inq[now]=false;
     For(i,0,siz)
     {
       adj &e=Edge[G[now][i]]; if (e.used) continue;
       if (dist[e.to]>max(dist[now],e.dist))
       {
         dist[e.to]=max(dist[now],e.dist);
         pa[e.to]=G[now][i];
         if (!inq[e.to])
         {
           Q.push(e.to);
           inq[e.to]=true;
         }
       }
     }
   }
   ans=max(ans,dist[n]);
   int x=n;
   while (x!=1)
   {
     Edge[pa[x]].used=Edge[pa[x]^1].used=true;
     x=Edge[pa[x]].from;
   }
}