[Euler Loop] HDU 3018 ant trip

Source: Internet
Author: User

Question link:

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3018

Ant trip Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1658 accepted submission (s): 641


Problem descriptionant country consist of N towns. There are m roads connecting the towns.

Ant Tony, together with his friends, wants to go through every part of the country.

They intend to visit every road, and every road must be visited for exact one time. however, it may be a mission impossible for only one group of people. so they are trying to divide all the people into several groups, and each may start at different town. now Tony wants to know what is the least groups of ants that needs to form to achieve their goal.
 
Inputinput contains multiple cases. test Cases are separated by several blank lines. each test case starts with two integer N (1 <= n <= 100000), m (0 <= m <= 200000 ), indicating that there are n towns and M roads in ant country. followed by M lines, each line contains two integers A, B, (1 <= A, B <= N) indicating that there is a road connecting town a and town B. no two roads will be the same, and there is no road connecting the same town.
Outputfor each test case, output the least groups that needs to form to achieve their goal.
Sample Input
3 31 22 31 34 21 23 4
 
Sample output
12HintNew ~~~ Notice: if there are no road connecting one town ,tony may forget about the town.In sample 1,tony and his friends just form one group,they can start at either town 1,2,or 3.In sample 2,tony and his friends must form two group. 
 
Source2009 multi-university training contest 12-host by fzu
Recommendgaojie | we have carefully selected several similar problems for you: 3013 3015 3016 3011
Statistic | submit | discuss | note

Question meaning:

To give an undirected graph, find the number of strokes you need and finish all the edges. The edges can only go once. Isolated points are not counted.

Solution:
DFS finds each connected block and counts the number of nodes with an odd number of degrees.

Note that isolated nodes are not counted.

Code:

// # Include <cspreadsheet. h> # include <iostream> # include <cmath> # include <cstdio> # include <sstream> # include <cstdlib> # include <string. h> # include <cstring> # include <algorithm> # include <vector> # include <map> # include <set> # include <stack> # include <list> # include <queue> # include <ctime> # include <bitset> # include <cmath> # define EPS 1e-6 # define INF 0x3f3f3f3f # define PI ACOs (-1.0) # define ll _ int64 # define ll Lo Ng long # define lson L, M, (RT <1) # define rson m + 1, R, (RT <1) | 1 # define M 1000000007 // # pragma comment (linker, "/Stack: 1024000000,1024000000") using namespace STD; # define maxn 111_int de [maxn], n, m; vector <vector <int> myv; int in [maxn], CNT; bool vis [maxn]; void DFS (INT cur) {in [++ CNT] = cur; vis [cur] = true; For (INT I = 0; I <myv [cur]. size (); I ++) {int Ne = myv [cur] [I]; If (vis [NE]) continue; DFS (NE) ;}} int main () {/ /Freopen ("in.txt", "r", stdin); // freopen ("out.txt", "W", stdout); While (~ Scanf ("% d", & N, & M) {myv. clear (); myv. resize (n + 10); memset (De, 0, sizeof (de); For (INT I = 1; I <= m; I ++) {int, b; scanf ("% d", & A, & B); myv [A]. push_back (B); myv [B]. push_back (a); De [a] ++; de [B] ++;} memset (VIS, false, sizeof (VIS); int ans = 0; for (INT I = 1; I <= N; I ++) {If (! Vis [I]) {CNT = 0; DFS (I); int temp = 0; If (CNT = 1) // The isolated node does not count as a continue; for (Int J = 1; j <= CNT; j ++) {If (de [in [J] & 1) temp ++; // printf ("I: % d J ")} If (! Temp) ans ++; else ans + = temp/2;} printf ("% d \ n", ANS) ;}return 0 ;}


[Euler Loop] HDU 3018 ant trip

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.