zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    EMV/PBOC解析(三) TLV格式解析(C#)
    写自己的WPF样式
    EMV/PBOC 解析(二) 卡片数据读取
    FLEX 图片拷贝
    重学浏览器(2)-进程间的交互
    重学浏览器(1)-多进程多线程的浏览器
    实现财务自由-《富爸爸穷爸爸》读书语句摘抄
    mini-css-extract-plugin简介
    egg.js路由的优雅改造
    node中异步IO的理解
  • 原文地址:https://www.cnblogs.com/taozi1115402474/p/8481418.html
Copyright © 2011-2022 走看看