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

why Time Limit Exceeded

Posted by huangtaiquan at 2007-12-05 19:08:10 on Problem 2395
#include<stdio.h>
#include<stdlib.h>

#define MAX 2100
#define max 1100000000

typedef struct {
	int date;
	int jihe;
}VEX;

typedef struct {
	int vexh;
	int vext;
	int weight;
	int flag;
}EDGE;

void minitree_KRUSKAL(void)
{  
	int n,i,m,min,k,j,tn;
    VEX t[2000];
    EDGE  e[10000];
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
    {  
		t[i].date=i;
		t[i].jihe=i;
    }
    for(i=0;i<m;i++)
    {  
		scanf("%d%d%d",&e[i].vexh,&e[i].vext,&e[i].weight);
		e[i].flag=0;
    }
    i=1;
    while(i<n)
    {  
		min=MAX;
		for(j=0;j<m;j++)
		{  
			if(e[j].weight<min && e[j].flag==0)
			 {  
				min=e[j].weight;
				k=j;
			}
		}
		tn=min;
		if(t[e[k].vexh].jihe!=t[e[k].vext].jihe)
		{   e[k].flag=1;
			for(j=1;j<=n;j++)
				if(t[j].jihe==t[e[k].vext].jihe)
				   t[j].jihe=t[e[k].vexh].jihe;
			t[e[k].vext].jihe=t[e[k].vexh].jihe;
				i++;
		}
		else
			  e[k].flag=2;
	}
	printf("%d\n",tn);
}

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