• HRBUST 2310 Tree Painting(无向图欧拉路径的性质)


    Give you a tree, can you draw the tree with minimum strokes without overlapping? Noted that it is ok if two strokes intersect at one point. Here we define a tree as a connected undirected graph with N points and N-1 edges.

    Input

    The input data has several test cases. The first line contains a positive integer T (T<=20), indicates the number of test cases.

    For each case:

    The first line contains an integers N (2<=N<=10^5), indicates the number of points on the tree numbered from 1 to N.

    Then follows N-1 lines, each line contains two integers Xi, Yi means an edge connected Xi and Yi (1<=Xi, Yi<=N).

    Output

    For each test case, you should output one line with a number K means the minimum strokes to draw the tree.

    Sample Input

    2

    2

    1 2

    5

    1 2

    1 5

    2 3

    2 4

    Sample Output

    1

    2

    题意

    给你一颗树,求需要用最少几笔才能画出整棵树

    题解

    由于是一颗树,任意两点都连通,所以最后只需要判断一幅图需要几笔画出

    判断是否无向图欧拉路径,只需要判断度数为奇数的节点数量g(0和2为1笔,其余为数量/2笔)

    一颗树的话奇点数g=0不存在

    代码

    #include<cstdio>
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int n,u,v,D[100005]={0};
            scanf("%d",&n);
            for(int i=1;i<n;i++)
            {
                scanf("%d%d",&u,&v);
                D[u]++;D[v]++;
            }
            int g=0;
            for(int i=1;i<=n;i++)
                if(D[i]%2==1)
                    g++;
            printf("%d
    ",g/2);
        }
        return 0;
    }
  • 相关阅读:
    299. Bulls and Cows
    C# 小知识
    C# Excel写入数据及图表
    C# 委托高级应用----线程——创建无阻塞的异步调用(二)
    C# 委托高级应用----线程——创建无阻塞的异步调用(一)
    C#中的GET和SET访问器
    C# 委托与事件详解(三)
    C# 委托与事件详解(二)
    C# 委托详解(一)
    Visual Studio 实用技能
  • 原文地址:https://www.cnblogs.com/taozi1115402474/p/8481418.html
Copyright © 2020-2023  润新知