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

WA的快疯掉了。。。。。。。。。。。。。。

Posted by zhougelin at 2005-06-19 11:18:26 on Problem 2202
program pku2202;
const inputfilename='';
      outputfilename='';
      maxn=10000;
      maxm=200000;
type tgraph=object
       total:longint;
       deg :array[1..maxn]of longint;
       edge:array[1..maxn]of longint;
       data:array[1..maxm]of longint;
       next:array[1..maxm]of longint;
       procedure addedge(u,v:longint);
            end;
var n,m,number,long:longint;
    g,ng:tgraph;
    belong:array[1..maxn]of longint;
    size  :array[1..maxn]of boolean;
    link  :array[1..maxm,1..2]of longint;
    visit :array[1..maxm]of boolean;
    path  :array[1..maxn]of longint;
procedure tgraph.addedge(u,v:longint);
begin
      inc(deg[u]);
      total:=total+1;
      data[total]:=v;
      next[total]:=edge[u];
      edge[u]:=total;
end;
procedure read_data;
var i,u,v:longint;
begin
      assign(input,inputfilename);
      reset(input);
      readln(n,m);
      for i:=1 to m do
      begin
         read(u,v);
         g.addedge(u,v);
         g.addedge(v,u);
      end;
      close(input);
end;
procedure dfs(u:longint);
var i,v:longint;
begin
      belong[u]:=number;
      i:=g.edge[u];
      while i>0 do
      begin
        v:=g.data[i];
        if (g.deg[v]>2) and (belong[v]=0) then
          dfs(v);
        i:=g.next[i];
      end;
end;
procedure noanswer;
begin
      assign(output,outputfilename);
      rewrite(output);
      writeln(-1);
      close(output);
      halt;
end;
procedure euler(u:longint);
var i,v:longint;
begin
      i:=ng.edge[u];
      while i>0 do
      begin
        v:=ng.data[i];
        if not visit[i] then
        begin
          visit[i]:=true;
          if odd(i) then visit[i+1]:=true else visit[i-1]:=true;
          if not size[u] then
          begin
            long:=long+1;
            path[long]:=link[i][1];
          end;
          long:=long+1;
          path[long]:=link[i][2];
          euler(v);
        end;
        i:=ng.next[i];
      end;
end;
procedure proceed;
var u,i,v:longint;
begin
      for u:=1 to n do
         if belong[u]=0 then
         begin
           inc(number);
           if g.deg[u]=2 then
           begin
             belong[u]:=number;
             size[number]:=true;
           end else dfs(u);
         end;
      for u:=1 to n do
      begin
         i:=g.edge[u];
         while i>0 do
         begin
           v:=g.data[i];
           if belong[u]<belong[v] then
           begin
             ng.addedge(belong[u],belong[v]);
             link[ng.total][1]:=u;link[ng.total][2]:=v;
             ng.addedge(belong[v],belong[u]);
             link[ng.total][1]:=v;link[ng.total][2]:=u;
           end;
           i:=g.next[i];
         end;
      end;
      for u:=1 to number do
         if odd(ng.deg[u]) then noanswer;
      euler(1);
end;
procedure print_answer;
var i:longint;
begin
      assign(output,outputfilename);
      rewrite(output);
      for i:=1 to n-1 do
         write(path[i],' ');
      writeln(path[n]);
      close(output);
end;
begin
      read_data;
      proceed;
      print_answer;
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