KAri OJ 92 Statistic node number adjacency table

Source: Internet
Author: User

92. Count the number of nodes time limit Ms Memory Limit 65536 KBTitle Description

Given a tree with a direction, there are altogether N ( 1<N≤ ) node, if the degree (degrees + degrees) of a node is not less than the degree of all its sons and its father (if there is a father or son), then we call this node the P node, and now your task is to count the number of P nodes.

For example, the first group has a P node of 0, and the second group has a P node.

Input format

Number of first-action data groups T ( 1≤T≤ )。
First behavior for each group of data N The number of nodes representing the tree. Followed by n 1 Rows, two numbers per line x , y ( 0 ≤ x y < n ), representing y Is x Son of a node.

Output format

Each set of data outputs a row, an integer representing the number of P nodes on the tree.

Input sample
250 11 22 33 430 20 1
Output sample
31
#include <stdio.h> #include <stdlib.h>int head[1001],du[1001],k;typedef struct edge{int v,next;} Edge;    Edge edge[2002];void addedge (int u,int v) {edge[k].v=v;    Edge[k].next=head[u]; head[u]=k++;}    int main () {int t;        while (~SCANF ("%d", &t)) {while (t--) {int n,i,j;        scanf ("%d", &n);        k=0;            for (i=0;i<=n;i++) {head[i]=-1;        du[i]=0;            } for (i=0;i<n-1;i++) {int u,v;            scanf ("%d%d", &u,&v);            Addedge (U,V);            Addedge (V,u);            du[u]++;        du[v]++;        } int sum=0;            for (i=0;i<n;i++) {int flag=0;                for (j=head[i];j!=-1;j=edge[j].next) {int v=edge[j].v;                    if (Du[i]<du[v]) {flag=1;                Break        }} if (!flag) sum++; } printf ("%d\n ", sum); }} return 0;}


KAri OJ 92 Statistic node number adjacency table

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.