Fake and real

Topic description

The earthquake is thunder, in the face of danger, it is not chaotic, and it is prosperous and smooth; the sun is the wind, which is soft and stretches, and bears all things.
Zhen Gua: Lei, Zhen, the gentleman cultivates province with fear. A golden bell was in the mud, and everyone was holding it as a stone to play with. Suddenly, the day clock was suspended, and the world knew it loudly.
Xun Gua: With the wind, Xun, the gentleman acts according to the order of Deuteronomy. A lonely boat falls on the beach, there are poles and no water, it is difficult to advance or retreat. 
The fortune teller asks you, for every undirected graph he gives, is there a path that goes through all the edges exactly once, and goes through all the points? There is no need to meet the final return to the starting point. 

Enter description:

The first line contains a number , indicating that there are groups of data. For each set of data, the first line has two numbers, and the next lines have two numbers per line to describe an undirected edge. Figure does not guarantee Unicom.

Output description:

For each set of data, if exists, output , otherwise output .

Example 1

enter

2
2 2
1 1
2 1
4 6
1 3
1 4
1 2
3 2
4 2
4 3

output

Zhen
Xun

Remark:

 
  
 
 
  
Problem- solving idea:   Because each edge needs to go through once, but the special point is that it can return to the starting point, or it can not go to the starting point. All Euler graphs are certainly satisfied, but so are semi-Eulerian graphs.
Established conditions: 1. The number of odd degrees in all points is 0 or 2 2. The graph is connected  
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    int p[205];
    int Find(int x)
    {return x==p[x]?x:p[x]=Find(p[x]);}
    int main()
    {
        int n,m,i,j,k,t,a,b,cnt;
        cin>>t;
        while(t--)
        {
            cin>>n>>m;
            cnt = 0 ;       // Store the connected edge 
            int degree[ 205 ]={ 0 };   // The degree of each point 
            for (i= 1 ;i<=n;i++) p[i]= i;
             for (i = 1 ;i<=m;i++ )
            {
                cin>>a>>b;
                degree[a]++;
                degree[b]++;
                int x=Find(a);
                int y=Find(b);
                if(x!=y)
                {
                    cnt++;
                    p[x]=y;
                }
            }
            k=0;
            for(i=1;i<=n;i++)
                if(degree[i]%2==1) k++;
            if((k==2||k==0)&&cnt==n-1) cout<<"Zhen\n";
            else cout<<"Xun\n";
        }
    }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324611570&siteId=291194637