ZOJ 1015 Fishing Net (judging the chord graph)

Source: Internet
Author: User

Title Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=15

Test instructions: given a graph. Judging is not a chord chart?

Idea: (1) God horse is a string diagram? For an image without a direction, if any one of the rings with a length greater than 3 has an edge connected to a two-point that is not adjacent to the ring, then this figure is called a chord graph.

(2) What is a regiment? A group is a sub-image of the original, and the sub-map contains some of the points of the original, so it is necessary to include the edges between those points. And the regiment is not a normal sub-figure but a complete sub-graph, that is, there are edges between any two vertices of the sub-graph. The following ABCD is a regiment of the original.


(3) Perfect elimination sequence: the sequence of a point of the original image (each point appears and happens exactly once) V1, v2,......, vn to meet {VI, vi+1,..., vn} The composition of the sub-diagram for the regiment.

(4) An no-show graph is a chord graph when and only if it has a perfect elimination sequence.

(5) How to calculate the perfect elimination sequence? The most popular algorithm: the order of the points from N to 1 sequentially (the point labeled I appears in the perfect elimination sequence of the first I). Set Label[i] indicates that the first point is adjacent to how many labeled points, each time you select Label[i] The largest unlabeled point to label. Note that the perfect elimination sequence is only calculated here, but it has not been decided after this is a chord graph.

(6) How to determine the original image from the perfect elimination sequence is not a chord chart? The simplest way is to determine, in turn, whether all the points adjacent to VI in the {vi+1,..., vn} constitute a regiment. This can be optimized by setting {vi+1,..., vn} where all the points adjacent to VI are VJ1,......, VJK. Simply determine if the vj1 is adjacent to the Vj2,......, vjk.

int n,m,g[n][n];int D[n],a[n],h[n],p[n];int OK () {    int i,j,u;    Vector<int> V;    FORL1 (i,n)    {        v.clear ();        FOR1 (J,n) if (G[a[i]][j]) if (p[j]>i) V.PB (j);        For (J=1;j<sz (V); j + +) if (P[v[0]]>p[v[j]])        {            swap (v[0],v[j]);        }        For (J=1;j<sz (V); j + +)        {            if (!g[v[0]][v[j]) return 0;}    }    return 1;} int main () {    Rush (n)    {        RD (m);        if (!n&&!m) break;        int i,j,k,u,v;        CLR (g,0);        FOR1 (i,m)        {            RD (u,v);            g[u][v]=g[v][u]=1;        }        CLR (d,0); CLR (h,0);        FORL1 (i,n)        {            u=-1;            FOR1 (J,n) if (!h[j]&&d[j]>u) u=d[j],k=j;            A[i]=k; H[k]=1; p[k]=i;            FOR1 (J,n) if (g[k][j]) d[j]++;        }        if (ok ())) puts ("Perfect");        Else puts ("imperfect");        Puts ("");    }    return 0;}

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.