Hdu1116&&poj1386

Source: Internet
Author: User
Tags in degrees

Links: Click to open link

Test instructions: Give some words to see whether the first phase

Code:

#include <iostream> #include <string.h> #include <algorithm> #include <stdio.h>using namespace                                       Std;int Fa[1005],in[1005],out[1005],vis[1005],temp[1005];char s[1005];int found (int x) {    Find root node if (x!=fa[x]) Fa[x]=found (fa[x]); return fa[x];} int main () {//have a direction connected graph D containing Oraton, when and only if the graph is a connected graph and D in addition to two nodes, the remaining of each node in degrees = out of degrees, int t,n,i,j,a,                               B,sign; And this two point satisfies deg-(u)-deg+ (v) =±1.                                     (The starting point s in degrees = out of 1, the exit of the end point T = the degree of penetration-1 or two points in the degree = the degree) scanf ("%d", &t); Many of the problems are not explained by some nouns, resulting in a lot of obstacles to see, the following explanation of the while (t--) {//In the meaning of this point is connected to the edge of this as the beginning of the number of points                                         , the inverse is the number of points for the end point cin>>n;            Oraton Road: Through all the edges in the diagram (no map or a direction graph), each side passes through only one pass as the Oraton Road for (i=0;i<1005;i++) {//Euler circuit: the corresponding circuit is called the Euler circuit.            Fa[i]=i;        in[i]=out[i]=vis[i]=0; } while (n--) {sCANF ("%s", s);                                 The problem is to judge whether the given word can close the link or become a a=s[0]-' a ' of the Euler loop;            Therefore, a word is regarded as an edge, the first two letters as two points, the degree of penetration and the degree of B=s[strlen (s) -1]-' a ';            Vis[a]=vis[b]=1;            in[a]++;out[b]++;        if (found (a)!=found (b))//Use and check to determine whether the map is connected, Euler access to determine the premise is the figure Unicom Fa[found (a)]=found (b);        } sign=0;            for (i=0;i<26;i++) if (vis[i]&&fa[i]==i) {sign++;        if (sign>1) break; The IF (sign>1) {//sign greater than 1 represents a point in addition to the root node that has no change to the root node, indicating that the graph is not connected to printf ("the door can        Not being opened.\n ");        Continue        } sign=0;        for (i=0;i<26;i++) {if (vis[i]&&in[i]!=out[i]) temp[sign++]=i; } if (sign==0) {//represents all points in and out equal to form the Euler loop printf ("Ordering is possible.\n")            ;        Continue } if (sign==2) {if ((in[temp[0]]-out[temp[0]]==1&&out[temp[1]]-in[temp[1]]==1) | |        (in[temp[1]]-out[temp[1]]==1&&out[temp[0]]-in[temp[0]]==1))              printf ("Ordering is possible.\n");        Determine the starting point s in degrees = out of 1, the exit of the end point t = in -1 else printf ("The door cannot be opened.\n");    } else printf ("The door cannot be opened.\n"); } return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hdu1116&&poj1386

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.