HIHO48: Oralu Yi

Source: Internet
Author: User
Tags in degrees

Time limit: 10000ms single point time limit: 1000ms memory limit: 256MB description

Little Hi and Little Ho are playing a decryption game recently, they need to take control of the characters in a primitive jungle to explore, collect props, and find the last treasure. Now the characters they control come to a big lake. There are n islets on the lake (ref. 1. N), as well as the M-seat bridge connecting the islets. Each wooden bridge has a treasure chest, which seems to contain what props.

Beside the lake there is a boatman, the Boatman told the protagonist. He can carry the protagonist to any island, and can be from any island to carry the protagonist back to the lake, but the protagonist has only one time back and forth opportunity. At the same time, the Boatman told the protagonist that the bridge between the islands is very fragile, after one pass will be broken off.

Because I do not know what props in the chest, small hi and small ho think that if you can put all the props collected is certainly the best, then for the current situation of the island and wooden bridge, can all props collected?

For example, a map consisting of 6 islets and 8 bridges:

The protagonist can reach the island of 4th, and then follow the order of 4->1->2->4->5->6->3->2->5 to reach the island of 5th, then the boatman to the island of 5th will lead back to the lake. This leads to the collection of all the props on the bridge.

Hint: Oralu's decision

Input

Line 1th: 2 positive integers, n,m. Indicates the number of islands and the number of wooden bridges respectively. 1≤n≤10,000,1≤m≤50,000

2nd.. M+1 lines: 2 integers per line, u,v. Indicates that a wooden bridge is connected to an island numbered U and V, and that there may be multiple bridges between the two islands. 1≤u,v≤n

Output

Line 1th: A string, if you can collect all the props output "full", otherwise output "part".

Sample input
6 81 21 42 42 52 33 64 55 6
Sample output
Full



Tips:
Hint: Oralu's decision

Little ho: Good trouble, it is my words to take a few steps, to no road can not go!

Small hi: In that case, the collection of props will be much less, if you want to use later, and have to re-read the document.

Little ho: Well, let me think about it first.

< two minutes after >

Little ho: This seems like a stroke of a question. Hey, we're asking a way to get all the edges out of a stroke?

Little hi: Yes, it's a stroke problem, but it's a more formal name called Euler's road problem. It is defined as

Given the no-orphaned node graph G, if there is a path, once per side of the diagram and only once, the path is called Euler Road.

Little ho: Since there is a name, it proves that this thing has a solution?

Little hi: Yes, Euler's path is conditional: an undirected graph exists Oralu when and only if the graph is connected and there are only 2 points in degrees that are odd, at which point the two points can only serve as the starting and ending points of the Euler path.

If there are no odd points in the graph, then the starting and ending points must be the same point, so the Euler path is called the Euro loop .

For any point, the number of times from other points to it and the number of times from it to other points are necessarily equal, otherwise the number of times and the number of entry will be different. If the number of entry, then the point of the end, if the number of out more than the point is the starting point.

For an out-of-direction graph, the number of incoming and outgoing times is exactly reflected in the amount of degrees. So the odd-numbered point can only have a maximum of 2.

Strict proof of the words:

If figure g is connected, there are 0 or two odd-point nodes, we always have the following method to construct a Euler road:

    1. If there are two odd number of nodes, then from one of the nodes to construct a trace, that is, from v[0] from the association edge E[1] "into" v[1 ", if the degree of v[1] is even, it will be v[1] and then by the associated side e[2] into the v[2], so go on, each side only take once. Since G is connected, it is necessary to stop at another odd few nodes and get a trace l:v[0]-e[1]-v[1]-e[2]...v[i]-e[i+1]...v[k]. If the G does not have an odd few nodes from any node v[0], the above method must be returned to the node v[0], the above a closed trace L1.
    2. If the L1 passes all the sides of G, then L1 is Euler's path.
    3. If the G to get rid of L1 after the sub-figure g′, then the g′ in the degree of each node is even, because the original diagram is connected, so L1 and g′ at least one node V[i] coincident, in g′ from v[i] start repeating the first step of the method, to get closure L2.
    4. When the L1 is combined with the L2, if it is G, then the Euler road is obtained, otherwise the third step can get the closed trace L3, and so on until a path is obtained from all sides of the graph G.

Consider the previous example:

For this diagram, the number of points numbered 4,5 is odd and the others are even. According to the nature of the above, we know that the starting and ending points must be 4, 5 nodes. Let's start at 4 and draw an edge until there's no way to go:

In this step we connect the 4-5-6-3-2-5. According to Oralu's construction, we got L1. Because L1 does not walk through all sides, so we perform step 3, we can find that for 4 and 2 is the sub-graph G ' coincident points, on the sub-chart we can get L2 (2-4-1-2):

The combination of L1 and L2 constitutes the Euler road.

Little ho: Since this is the nature, I just need to calculate the degree of each point to know if I can walk through all sides.

Little hi: Yes, but don't forget the most important point is that the whole diagram is connected.

1#include <iostream>2#include <vector>3 4 using namespacestd;5 6 voidDFS (vector<vector<int> >& Graph,inti,vector<BOOL>& visited,int&CNT)7 {8     if(i>=graph.size ())9     {Ten         return; One     } A  -     intSZ =graph.size (); -  the     if(!Visited[i]) -     { -Visited[i] =true; -cnt++; +          for(intj =0; J<graph[i].size (); J + +) -         { +             if(!Visited[graph[i][j]]) A DFS (Graph, Graph[i][j], visited, CNT); at         } -     } - } -  - BOOLIsconnectedgraph (vector<vector<int> >&Graph) - { in     intSZ =graph.size (); -vector<BOOL> Visited (SZ,false); to      +     intCNT =0; -DFS (Graph,0, visited, CNT); the     if(cnt<sz) *         return false; $     return true;Panax Notoginseng } -  the intMain () + { A     intN, M; theCin>>n>>M; +vector<int>Edge; -vector<vector<int> >Graph (N, edge); $vector<int> Degree (N,0); $  -     intI=M; -      while(i--) the     { -         intA, B;WuyiCin>>a>>b; thea--; -b--; Wu Graph[a].push_back (b); -degree[a]++; Aboutdegree[b]++; $     } -  -     intCntofodd =0; -  A      for(intI=0; i<n; i++) +     { the         if(degree[i]%2==1) -cntofodd++; $     } the     if(cntofodd!=2&& cntofodd!=0) thecout<<" Part"; the     Else the     { -         if(Isconnectedgraph (Graph)) incout<<" Full"; the         Else thecout<<" Part"; About     } the  the      the     return 0; +}
View Code

HIHO48: Oralu Yi

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.