记录编号 118318 评测结果 AAAAAAAAAA
题目名称 [USACO Feb07] 奶牛聚会 最终得分 100
用户昵称 GravatarHouJikan 是否通过 通过
代码语言 C++ 运行时间 0.008 s
提交时间 2014-09-06 10:40:26 内存使用 0.35 MiB
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#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 to,dist;
  adj(int to=0,int dist=0):to(to),dist(dist){}
};
//==============var declaration=================
const int MAXN=1010;
int n,m,s;
int d1[MAXN],d2[MAXN];
bool inq[MAXN];
vector <adj> Edge1[MAXN],Edge2[MAXN];
//==============function declaration============
void spfa(vector <adj> *Edge,int *d);
//==============main code=======================
int main()
{  
  string FileName="sparty";//程序名 
  string FloderName="COGS";//文件夹名 
  freopen((FileName+".in").c_str(),"r",stdin);
  freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG  
  system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
  clock_t Start_Time=clock();
#endif    
  scanf("%d%d%d",&n,&m,&s);
  int from,to,dist;
  For(i,1,m)
  {
    scanf("%d%d%d",&from,&to,&dist);
    Edge1[from].push_back(adj(to,dist));
    Edge2[to].push_back(adj(from,dist));
  }
  spfa(Edge1,d1);
  spfa(Edge2,d2);
  int maxt=0;
  For(i,1,n)
    maxt=max(maxt,d1[i]+d2[i]);
  cout<<maxt<<endl;
#ifdef DEBUG  
  clock_t End_Time=clock();
  cout<<endl<<endl<<"Time Used: "<<End_Time-Start_Time<<endl;
#endif    
  return 0;
}
//================fuction code====================
void spfa(vector <adj> *Edge,int *d)
{
  For(i,1,n)
    d[i]=INF;
  d[s]=0;
  queue <int>Q;
  Q.push(s);
  memset(inq,false,sizeof(inq));
  while (!Q.empty())
  {
    int now=Q.front();Q.pop();
    inq[now]=false;
    int siz=Edge[now].size()-1;
    For(i,0,siz)
    {
      adj &e=Edge[now][i];
      if (d[e.to]>d[now]+e.dist)
      {
        d[e.to]=d[now]+e.dist;
        if (!inq[e.to])
          Q.push(e.to);
        inq[e.to]=true;
      }
    }
  } 
}