# [BZOJ1631][Usaco2007 Feb]Cow Party

## 1631: [Usaco2007 Feb]Cow Party

Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 870  Solved: 628 [Submit][Status][Discuss]

## Description

农场有N(1≤N≤1000)个牛棚，每个牛棚都有1只奶牛要参加在X牛棚举行的奶牛派对．共有M(1≤M≤100000)条单向路连接着牛棚，第i条踣需要Ti的时间来通过．牛们都很懒，所以不管是前去X牛棚参加派对还是返回住所，她们都采用了用时最少的路线．那么，用时最多的奶牛需要多少时间来回呢？

## Input

第2行到第M+1行,每行三个用空格隔开的整数:Ai, Bi,以及Ti.表示一条道路的起点,终点和需要花费的时间.

4 8 2
1 2 4
1 3 2
1 4 7
2 1 1
2 3 5
3 1 2
3 4 4
4 2 3

10

## HINT

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char buf[10000000], *ptr = buf - 1;
int n = 0;
char ch = *++ptr;
while(ch < '0' || ch > '9') ch = *++ptr;
while(ch <= '9' && ch >= '0'){
n = (n << 1) + (n << 3) + ch - '0';
ch = *++ptr;
}
return n;
}
const int maxn = 100000 + 10, maxm = 100000 + 10;
struct Edge{
int to, val, next;
Edge(){}
Edge(int _t, int _v, int _n): to(_t), val(_v), next(_n){}
}e[maxm * 2];
int fir[maxn] = {0}, Fir[maxn] = {0}, cnt = 0;
inline void add1(int u, int v, int w){
e[++cnt] = Edge(v, w, fir[u]); fir[u] = cnt;
}
inline void add2(int u, int v, int w){
e[++cnt] = Edge(v, w, Fir[u]); Fir[u] = cnt;
}
int n, m, x;
bool inq[maxn] = {false};
int dis1[maxn], dis2[maxn];
int q[maxn], h, t;
void spfa1(){
memset(dis1, 0x3f, sizeof dis1);
dis1[x] = 0;
h = t = 0;
q[t++] = x;
int u, v;
while(h != t){
u = q[h++]; if(h == 100010) h = 0;
inq[u] = false;
for(int i = fir[u]; i; i = e[i].next){
v = e[i].to;
if(dis1[v] > dis1[u] + e[i].val){
dis1[v] = dis1[u] + e[i].val;
if(!inq[v]){
inq[v] = true;
q[t++] = v;
if(t == 100010) t = 0;
}
}
}
}
}
void spfa2(){
memset(dis2, 0x3f, sizeof dis2);
dis2[x] = 0;
h = t = 0;
q[t++] = x;
int u, v;
while(h != t){
u = q[h++]; if(h == 100010) h = 0;
inq[u] = false;
for(int i = Fir[u]; i; i = e[i].next){
v = e[i].to;
if(dis2[v] > dis2[u] + e[i].val){
dis2[v] = dis2[u] + e[i].val;
if(!inq[v]){
inq[v] = true;
q[t++] = v;
if(t == 100010) t = 0;
}
}
}
}
}
int main(){
for(int u, v, w, i = 1; i <= m; i++){
}