| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
无脑dijkstra水过。。。#include<bitset>
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
const int INF=1e9;
const int MAX_V=1000+7;
const int MAX_E=100000+7;
int m,t,x,ans;
struct edge{
int to,cost;
};
typedef pair<int,int> P;
int V;
vector<edge> G[MAX_V];
int d[MAX_V];
int data1[MAX_V],data2[MAX_V];
void dijkstra(int s){
priority_queue<P,vector<P>,greater<P> > que;
fill(d,d+V+1,INF);
d[s]=0;
que.push(P(0,s));
while (!que.empty())
{
P p=que.top();que.pop();
int v=p.second;
if(d[v]<p.first)continue;
for (unsigned int i = 0; i < G[v].size(); i += 1)
{
edge e=G[v][i];
if(d[e.to]>d[v]+e.cost){
d[e.to]=d[v]+e.cost;
que.push(P(d[e.to],e.to));
}
}
}
}
int main()
{
scanf("%d%d%d",&V,&m,&x);
int a;edge ex;
for (int i = 0; i < m; i += 1)
{
scanf("%d%d%d",&a,&ex.to,&ex.cost);
G[a].push_back(ex);
}
dijkstra(x);
for (int i = 1; i <= V; i += 1)data1[i]=d[i];
for (int i = 1; i <= V; i += 1){dijkstra(i);data2[i]=d[x];}
for (int i = 1; i <= V; i += 1)ans=max(ans,data1[i]+data2[i]);
printf("%d\n",ans);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator