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

为什么运行错误

Posted by 826529615 at 2011-09-09 23:20:24 on Problem 3522
type
  rec = record
    x, y, d: longint;
  end;

var
  n, m, i, now, ans, min, max: longint;
  e: array[0..55010] of rec;
  f: array[0..1000] of longint;

procedure qs(l, r: longint);
var
  i, j, mid: longint;
  t: rec;
begin
  i := l;
  j := r;
  mid := e[(l+r) div 2].d;
  repeat
    while e[i].d < mid do inc(i);
    while e[j].d > mid do dec(j);
    if i <= j then
      begin
        t := e[i];
        e[i] := e[j];
        e[j] := t;
        inc(i);
        dec(j);
      end;
  until i > j;
  if l < j then qs(l,j);
  if i < r then qs(i,r);
end;

function get(k: longint):longint;
begin
  if f[k] = k then exit(k);
  f[k] := get(f[k]);
  get := f[k];
end;

procedure kur(st: longint);
var
  i, p, x, y: longint;
begin
  p := 0;
  for i := 1 to n do f[i] := i;
  i := st;
  min := e[st].d;
  while (p < n-1) or (i <= m) do
    begin
      x := get(e[i].x);
      y := get(e[i].y);
      if x <> y then
        begin
          f[x] := y;
          max := e[i].d;
          inc(p);
        end;
      inc(i);
    end;
  if p <> n-1 then now := maxlongint else now := max-min;
end;

begin
  readln(n,m);
  while not((n = 0) and (m = 0)) do
    begin
      //fillchar(e,sizeof(e),0);
      for i := 1 to m do
        readln(e[i].x,e[i].y,e[i].d);
      qs(1,m);
      ans := maxlongint;
      for i := 1 to m-n+2 do
        begin
          kur(i);
          if now < ans then ans := now;
        end;
      if ans = maxlongint then writeln(-1) else writeln(ans);
      readln(n,m);
    end;
end.

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