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 |
好奇怪,一直WA,求求大家能不能帮忙看一下啊,调崩溃了,自信没问题的~~~~(>_<)~~~~#include<stdio.h> #include<iostream> #include<string.h> #include<queue> using namespace std; int n,m,x; int dir[1010][1010]; int dir_go[1010][1010]; struct Node{ int num; int weight; bool operator<(const Node &a)const{ if(weight==a.weight) return num > a.num; return weight>a.weight; } }; int ans[1010][1010]; int maxnum=0; int a,b,c; int ans_go[1010][1010]; priority_queue<Node>q; Node firstnode; Node thisnode; Node nextnode; int main() { while(scanf("%d%d%d",&n,&m,&x)!=EOF){ memset(dir,0x3f,sizeof(dir)); memset(ans,0x3f,sizeof(ans)); memset(ans_go,0x3f,sizeof(ans_go)); memset(dir_go,0x3f,sizeof(dir_go)); for(int i=0;i<m;i++){ scanf("%d%d%d",&a,&b,&c); dir[a][b]=c; dir_go[b][a]=c; } for(int i=1;i<=n;i++){ dir[i][i]=0; ans[i][i]=0; dir_go[i][i]=0; ans_go[i][i]=0; } // int i=x; firstnode.num=x; firstnode.weight=0; q.push(firstnode); while(!q.empty()){ thisnode=q.top(); q.pop(); for(int j=1;j<=n;j++){ if(ans[x][j]>thisnode.weight+dir[thisnode.num][j]){ ans[x][j]=thisnode.weight+dir[thisnode.num][j]; nextnode.num=j; nextnode.weight=ans[x][j]; q.push(nextnode); } } } firstnode.num=x; firstnode.weight=0; q.push(firstnode); while(!q.empty()){ thisnode=q.top(); for(int j=1;j<=n;j++){ if(ans_go[x][j]>thisnode.weight+dir_go[thisnode.num][j]){ ans_go[x][j]=thisnode.weight+dir_go[thisnode.num][j]; nextnode.num=j; nextnode.weight=ans_go[x][j]; q.push(nextnode); } } q.pop(); } maxnum=0; for(int i=1;i<=n;i++){ if(maxnum<ans[x][i]+ans_go[x][i]) maxnum=ans[x][i]+ans_go[x][i]; } printf("%d\n",maxnum); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator