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

Please help, why I got run time error?

Posted by xiaoqiangwj at 2008-11-09 23:54:48 on Problem 2485
#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

int t[501];

struct E{
  int p;
  int n;
  int w;
}e[2510];

int cmp(E e1,E e2){
  return e1.w>e2.w;
}

int find( int x){
  if (x!=t[x]) return t[x]=find(t[x]);
  return t[x];
}

int main(){
  int i,j,k,tc,numE,result,numC,numV,u,v;
  cin >>numC;
  for (i=0;i<numC;i++){
    result=numE=0;
    for (i=0;i<501;i++) t[i]=i;
    cin >>numV;
    for (j=0;j<numV;j++){
      for (k=0;k<numV;k++){
        e[numE].p=j;
        e[numE].n=k;
        scanf("%d",&(e[numE++].w));
       }
     }
      
     tc=numE;
     make_heap(e,e+numE,cmp);
     result=e[0].w;
     for (i=0;i<numV;tc--){
       if(!tc) break;
       if ((u=find(e[0].p)) != (v=find(e[0].n))){
         t[u]=v;
         if (result<e[0].w) result=e[0].w;
         i++;
       }
       pop_heap(e,e+tc,cmp);
    }
    cout <<result<<endl;
  }
  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