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 |
why Time Limit Exceeded#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator