Minimum dictionary sequence of a topological Sequence

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.