Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么数据都过了还A不了啊,,,,纠结啊啊啊啊啊啊啊啊,,大婶(神)们请指正啊

Posted by 2010030402005 at 2011-07-31 17:03:54 on Problem 2457
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#define MAXN 2000
using namespace std;
struct ArcNode
{
  int to;
  struct ArcNode *next;
};
ArcNode* List[MAXN];
int visit[MAXN];
int num[MAXN];
int main()
{
  int n,m;
  int u,v;
  int hehe;
  int tt=1;
  int aa;
  scanf("%d%d",&n,&m);
  hehe=m;
  memset(List,0,sizeof(List));
  memset(visit,0,sizeof(visit));
  memset(num,0,sizeof(num));
  ArcNode* temp;
  for(int i=1;i<=n;i++)
    {
      scanf("%d%d",&u,&v);
      temp=new ArcNode;
      temp->to=v;
      temp->next=NULL;
      if(List[u]==NULL)
	List[u]=temp;
      else
	{
	  temp->next=List[u];
	  List[u]=temp;
	}
    }
  ArcNode* tt1;
 


  queue<ArcNode *>q;
  int sum[MAXN];
  int lujin[MAXN];
  int tem;
  int biao;
  biao=1;
 temp=List[1];
  visit[1]=-1;
  sum[1]=1;
  tem=1;
  int i=1;
   q.push(temp);
  ArcNode* node;
  node=q.front();


  while(!q.empty())
   {
    q.pop();
     if(node->to==m)
       {
	 tt=0;
	 printf("%d\n",sum[m]);
	 while(num[m])
	   {
	     lujin[i]=num[m];
	     m=num[m];
	     i++;
	   }
	 for(int j=i-1;j>=1;j--)
	   {
	     printf("%d\n",lujin[j]);
	   }
	 printf("%d\n",hehe);
	 break;
       }


     while(node!=NULL)
       {
	 if(visit[node->to]!=-1)
	   {
	     sum[node->to]=sum[tem]+1;
	     num[node->to]=biao;
	     biao=node->to;
	 q.push(node);
	 visit[node->to]=-1;
	   }
	 node=node->next;
       }
       node=q.front();
       tem=node->to;
       node=List[node->to]; 
       if(node->to==m)
	 {
	   num[node->to]=tem;
	   sum[node->to]=sum[tem]+1;
	 }
    }


  if(tt==1)
    printf("-1\n");
  return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator