Error Checking
Another sign-in question is written in the test room...
We found that this question requires a minimum dictionary sequence.
Obviously, it is not advisable to locate all sequences and then sort them,
So we cannot use the common Topology Sorting method. How can we maintain the topology order each time?
Use a small root heap to maintain a point with an inbound degree of 0. The inbound level is counted during input.
{$inline on}const maxn=100010;type node=record pos,next:longint;end;var heap,getin,head,ans:array[0..maxn] of longint; edge:array[0..maxn*2] of node; n,m,cnt,top:longint; check:boolean;procedure add(u,v:longint); inline;begin inc(cnt); edge[cnt].pos:=v; edge[cnt].next:=head[u]; head[u]:=cnt;end;procedure swap(var a,b:longint); inline;begin a:=a xor b; b:=a xor b; a:=a xor b;end;procedure up(i:longint); inline;var j:longint;begin j:=i>>1; while j>0 do begin if heap[i]View code
Minimum dictionary sequence of a topological Sequence