题解

3 条题解

  • -3
    @ 2022-07-14 14:43:56

    tai niu le

  • -7
    @ 2015-12-16 17:58:30

    const maxn=2000+10;maxm=10000+10;
    type node=record
    go,next:longint;
    end;
    var head,deg,inp,a,b,q:array[0..maxn] of longint;
    h,t,i,n,m,x,y:longint;
    e:array[0..maxm] of node;
    procedure sort(l,r:longint);
    var i,j,m,temp:longint;
    begin
    i:=l;j:=r;x:=a[(i+j)>>1];
    repeat
    while b[a[i]]<b[x] do inc(i);
    while b[a[j]]>b[x] do dec(j);
    if i<=j then
    begin
    y:=a[i];a[i]:=a[j];a[j]:=y;
    inc(i);dec(j);
    end;
    until i>j;
    if i<r then sort(i,r);
    if j>l then sort(l,j);
    end;
    procedure init;
    begin
    readln(n,m);
    for i:=1 to n do
    begin
    read(b[i]);
    b[i]:=n-b[i];
    a[i]:=i;
    end;
    sort(1,n);
    for i:=1 to m do
    begin
    readln(y,x);
    e[i].go:=y;inc(inp[y]);e[i].next:=head[x];head[x]:=i;
    end;
    end;
    procedure work(x:longint);
    var i,p,j,u,v:longint;
    begin
    deg:=inp;
    h:=0;t:=0;p:=1;
    for i:=1 to n do
    begin
    while (p<=n) and (b[a[p]]<i) do
    begin
    v:=a[p];
    if (deg[v]=0) and (v<>x) then
    begin
    inc(t);q[t]:=v;
    end;
    inc(p);
    end;
    if h<t then
    begin
    inc(h);
    u:=q[h];
    j:=head[u];
    while j<>0 do
    begin
    v:=e[j].go;
    dec(deg[v]);
    if (deg[v]=0) and (v<>x) and (b[v]<i) then
    begin
    inc(t);q[t]:=v;
    end;
    j:=e[j].next;
    end;
    end
    else exit;
    end;
    end;
    procedure main;
    begin
    work(0);
    for i:=t downto 1 do write(q[i],' ');writeln;
    for i:=1 to n do
    begin
    work(i);
    write(n-t,' ');
    end;
    end;
    begin
    assign(input,'input.txt');assign(output,'output.txt');
    reset(input);rewrite(output);
    init;
    main;
    close(input);close(output);
    end.

  • -8
    @ 2015-03-05 13:22:01

    沙发

  • 1

信息

ID
1819
难度
10
分类
(无)
标签
递交数
188
已通过
0
通过率
0%
被复制
4
上传者