FZU2112 tickets (and check set + Oraton Road) Classic

Source: Internet
Author: User

Problem 2112 Ticketsaccept:309 submit:526
Time limit:3000 mSec Memory limit:32768 KB problem Description

You are won a collection of tickets on luxury cruisers. Each ticket can is used only once, but can is used in either direction between the 2 different cities printed on the Ticke T. Your Prize gives you free airfare to all city to start Your cruising, and free airfare back home from wherever you fini SH your cruising.

Sail and Don ' t want to waste any of the your free tickets. How many additional tickets would are you having to buy so, your cruise can use all of your tickets?

Now giving the free tickets you have won. Please compute the smallest number of additional tickets so can be purchased-to-allow-all of your free ticket S.

Input

There is an integer T (t≤100) in the first line of the input.

Then T-cases, for any case, the first line contains 2 integers n, m (1≤n, m≤100,000). n indicates the identifier of the cities is between 1 and N, inclusive. M indicates the tickets you have won.

Then following m lines, each line contains the integers u and V (1≤u, v≤n), indicates the 2 cities printed on your tickets , respectively.

Outputfor each test case, output an integer-in-A, indicates the smallest number of additional tickets you need To buy. Sample INPUT3
5 31 31) 24 5
6 51 31 21 61 51 4
3 2 Sample Output120 Source "Higher Education Cup" the third Fujian University student Program Design Competition
#include <stdio.h> #include <string.h>const int N = 100005;int edgn,fath[n];int findobj (int x) {if (x!=fath[x]    ) Fath[x]=findobj (fath[x]); return fath[x];}    void Setnode (int u,int v) {u=findobj (U);    V=findobj (v);        if (u!=v) {edgn--;    Fath[u]=v;    }}int Main () {int t,linkedgn[n],ans,n,m,u,v;    scanf ("%d", &t);        while (t--) {scanf ("%d%d", &n,&m);        for (int i=0;i<=n; i++) {fath[i]=i; linkedgn[i]=0; } edgn=0;//the difference between the record point and the edge ans=0;//the number of vertices with odd degrees of vertices while (m--) {scanf ("%d%d", &u,&v)            ;            if (linkedgn[u]==0) edgn++;            if (linkedgn[v]==0) edgn++;                        Setnode (U,V);            linkedgn[u]++;            linkedgn[v]++; if (linkedgn[u]&1) ans++;            else ans--; if (linkedgn[v]&1) ans++;        else ans--; } edgn--;//the minimum number of edges to make the point appear as a connected graph ans-= (edgn+1) *2;//add edge and the figure remainsThe degree of the ANS point is the singularity vertex (minus two starting and ending points for the singularity) ans/=2;        The remaining points are in the odd degree of the number of vertices 22 connected if (ans<0) printf ("%d\n", EDGN);    else printf ("%d\n", Edgn+ans); }}


FZU2112 tickets (and check set + Oraton Road) Classic

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.