| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 10102 | Accepted: 4489 |
Description
One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤X ≤N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; roadi requiresTi (1 ≤ Ti ≤ 100) units of time to traverse.
Each cow must walk to the party and, when the party is over, return to her farm. Each cow is lazy and thus picks an optimal route with the shortest time. A cow's return route might be different from her original route to the party since roads are one-way.
Of all the cows, what is the longest amount of time a cow must spend walking to the party and back?
Input
Lines 2..M+1: Line i+1 describes road i with three space-separated integers:Ai,Bi, and Ti. The described road runs from farmAi to farmBi, requiring Ti time units to traverse.
Output
Sample Input
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
Sample Output
10
Hint
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
const int INF=10000000;
int n,x;
int map[1005][1005];
int dis[1005];
bool vis[1005];
int back[1005]; //保存回去时终点到各点的最短距离
int go[1005]; //保存各点到终点的最短距离
void dij(int d[])
{
memset(vis,false,sizeof(vis));
for(int i=1;i<=n;i++)
dis[i]=map[x][i];
vis[x]=true;
for(int i=1;i<=n;i++)
{
int x,min=INF;
for(int j=1;j<=n;j++)
if(!vis[j]&&dis[j]<min)
min=dis[x=j];
if(min==INF) break;
vis[x]=true;
for(int j=1;j<=n;j++)
if(!vis[j]&&dis[j]>dis[x]+map[x][j])
dis[j]=dis[x]+map[x][j];
}
for(int i=1;i<=n;i++)
d[i]=dis[i];
}
int main()
{
int m,a,b,t;
while(scanf("%d%d%d",&n,&m,&x)!=EOF)
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if(i==j) map[i][j]=0;
else
map[i][j]=INF;
}
while(m--)
{
scanf("%d%d%d",&a,&b,&t);
map[a][b]=t;
}
dij(back);
for(int i=1;i<=n;i++) //将矩阵转置
for(int j=i+1;j<=n;j++)
{
int temp=map[i][j];
map[i][j]=map[j][i];
map[j][i]=temp;
}
dij(go);
int max=0;
for(int i=1;i<=n;i++)
{
if(back[i]+go[i]>max)
max=back[i]+go[i];
}
printf("%d\n",max);
}
return 0;
}

本文深入探讨了深度学习在人工智能领域的应用,包括卷积神经网络、循环神经网络、强化学习等关键技术,以及它们在图像处理、自然语言处理、推荐系统等实际场景中的实践案例。
349

被折叠的 条评论
为什么被折叠?



