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

为啥总是mle,不明白啊,

Posted by liffeng at 2007-07-08 23:11:41 on Problem 3249
#include<iostream>
#include<math.h>
using namespace std;
#define Maxn 100001
//#define Maxm 100001
int w[Maxn],n,m;
__int64 sum,max=-999999999;
int color[Maxn];  
struct node
{
	int v;     //邻接点,或者出度值
	int d;  //入度值

	struct node *next;
};
struct node graph[Maxn];
void Insert(int a,int b)
{
	struct node *p;
	p=(node*)malloc(sizeof(node));
	p->v=b;
	graph[a].v++;
	graph[b].d++;
	p->next=graph[a].next;
	graph[a].next=p;
}

void dfs(int s)
{
	
    if(graph[s].v==0)
	{
         if(max<sum)
			 max=sum;
	}
	struct node *p;
	p=(node*)malloc(sizeof(node));
	p=graph[s].next;
	while(p!=NULL)
	{
		
		if(color[p->v]==0)
		{
			sum+=w[p->v];
		   color[p->v]=1;
		   dfs(p->v);
		   color[p->v]=0;
		   sum-=w[p->v];
		}
      p=p->next;
	}
	color[s]=2;
	free(p);
}
void liffeng()
{
     int i;
	 memset(color,0,sizeof(color));
	 
	 for(i=1;i<=n;i++)
	 {
		 if(color[i]!=2&&graph[i].d==0)
		 {
			 sum=w[i];
			 dfs(i);
		 }
	 }
	printf("%I64d\n",max);
}
void makemap()
{
	int i,a,b;

	freopen("in.txt","r",stdin);

   while(cin>>n>>m)
   {
		for(i=1;i<=n;i++)
			 graph[i].d=graph[i].v=0;
		for(i=1;i<=n;i++)
			cin>>w[i];
		
		for(i=1;i<=m;i++)
		{
			cin>>a>>b;
			Insert(a,b);
		//	delet();
		}
		liffeng();
   }

}
int main()
{
	makemap();
	
	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