"ZOJ" 1015 Fishing Net

Source: Internet
Author: User

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1015

Test instructions: Gives an n-point-free graph asking whether it is a string, and the string is defined as having an edge connected to an adjacent point on the ring of an arbitrary length >3 in the graph (n<=1000)

#include <bits/stdc++.h>using namespace Std;const int n=1005;int N, M, Ihead[n], CNT, tag[n], Pos[n];bool vis[n];str UCT E {int next, to;} e[n*n];void Add (int u, int v) {E[++cnt]={ihead[u], v}; Ihead[u]=cnt;e[++cnt]={ihead[v], u}; ihead[v]=cnt;} void Cln () {memset (ihead, 0, sizeof (int) * (n+1)), memset (tag, 0, sizeof (int) * (n+1)), memset (POS, 0, sizeof (int) * (n+1)); cnt=0;} BOOL Check () {int x, Y, MN, mx;for (int now=n; now;--now) {mx=-1; mn=~0u>>1; x=y=0;for (int i=1; i<=n; ++i) if (!po S[i] && tag[i]>mx) mx=tag[i], x=i;pos[x]=now;for (int i=ihead[x]; i; i=e[i].next) if (!pos[e[i].to]) tag[e[i]. to]++;for (int i=ihead[x]; i; i=e[i].next) if (pos[e[i].to]>pos[x] && pos[e[i].to]<mn) mn=pos[e[i].to], y= e[i].to;for (int i=ihead[y]; i; i=e[i].next) vis[e[i].to]=1; vis[y]=1;for (int i=ihead[x]; i; i=e[i].next) if (Pos[e[i].to]>pos[x] &&!vis[e[i].to]) return 0;for (int i= Ihead[y]; I I=e[i].next) vis[e[i].to]=0; vis[y]=0;} return 1;} int main () {while (scanf ("%d%d", &n, &m), n&&m) {int x, y;for (int i=0; i<m; ++i) {scanf ("%d%d", &x, &y); Add (x, y);} Check ()? puts ("Perfect"):p UTS ("imperfect"); Puts (""); Cln ();} return 0;}

  

String Graph judging naked question = = Detailed view of CDQ's thesis = = "Chord and Interval map"

Chord Graph definition above said = =

Here's a look at the nature:

Regiment: A complete picture, in which any point pair in a regiment is connected by a side.

Simple point: If $x$ and its adjacent points make up a regiment, then $x$ is a simple point.

Perfect elimination sequence: a sequence of points, with each point appearing and once, and satisfying for any $v_i$, $v_i$ is a simple point in the $v_{i+1} \cdots v_{n}$ induced sub-graph.

Theorem 1: A chord graph has at least one perfect elimination sequence. (Proof to see thesis)

Theorem 2: The induced sub-graph of a string graph is also a chord graph

So the algorithm of naked searching for perfect sequence is to try to join the perfect sequence of the current maintenance to see if it is a simple point if it is not in the perfect sequence at each time. Of course this is naked violence = =

So CDQ paper introduces two algorithms = = one is dictionary sequence BFS. One is the most popular algorithm, because I see the online implementation are the most popular algorithm (MCS algorithm) = = So I learned the most trend is OK. Anyway, both algorithm complexity is $o (n+m) $

First, the MCS principle is to find a sequence and then determine whether this is a perfect elimination sequence. So how does the MCS algorithm find a sequence?

Ghosts know! Anyway, looks like this is a kind of greedy QAQCDQ paper also does not explain qaq, each time to the perfect sequence before adding a point, and each time the point is added to the current maintenance sequence of points in the most not in the sequence of points = = what the hell!

So the algorithm is to find the points in the sequence with the most points in the series not the point in the sequence, adding = =

Finally determine whether the sequence is legal:

If we want to judge $v_i$ this point, that is, in $v_{i+1} \cdots v_{n}$ to find the $v_i$ adjacent to the point set $v_{j_1}, v_{j_2}, \cdots v_{j_k}$, and is in the order of the sequence from small to large order. Then we only need to judge $v_{j_1}$ and $v_{j_i}, i>1$ whether there is an edge to connect to, if not, this figure is not a string diagram. Since this is added sequentially to the sequence, and we ask that the point set be a regiment, then obviously we just need to determine whether the first $v_{j_1}$ in the sequence is connected to the other, because $v_{j_i}, i>1$ has already been judged = =

At the point of finding the most connected edge that step, is able to use the list to optimize to $o (1) $, but I am too lazy, direct violence = = Anyway the subject can be too ... Even without $o (1) $, we can also use set = =

"ZOJ" 1015 Fishing Net

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.