日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

2020牛客国庆集训派对day3 Points

發(fā)布時(shí)間:2023/12/3 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2020牛客国庆集训派对day3 Points 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Points

題目描述

Jack and Rose are playing games after working out so many difficult problems. They together drew a “Haizi” tree to show their collaboration. “Haizi” tree is the same as the tree defined in graph theory.

Now Jack would like to count the number of vertices whose degree is one in this tree. You need to help him with this calculation.

\textit{Degree}Degree: The degree of a vertex of a graph is the number of edges that are connected with the vertex.

輸入描述:

The first line contains an integer {n}n (2 \leq n \leq 10^52≤n≤10
5
) — the number of vertices.
The next {n-1}n?1 lines describe the edges of the tree, where the {i}i-th line contains two integers x_i≤n) — the two vertices that is connected by the {i}i-th edge.

輸出描述:

Output one integers in one line — the number of vertices whose degree is one.
示例1
輸入
復(fù)制

5 1 2 2 3 1 4 4 5

輸出
復(fù)制

2

說明
As shown in figure below, only the vertex {3}3 and vertex {5}5 are connected with only one edge. So there are {2}2 vertices whose degree is one.

題解:

題目很簡單就是問度為1的點(diǎn)有多少?
每輸入一個(gè)邊,就讓兩個(gè)點(diǎn)的度數(shù)+1,最后記錄有多少點(diǎn)的度數(shù)為1

代碼:

#include<bits/stdc++.h> using namespace std; const int maxn=1e5+8; int odd[maxn]; int main() {int n;cin>>n;for(int i=1;i<n;i++){int x,y; cin>>x>>y;odd[x]++;odd[y]++;}int sum=0;for(int i=1;i<=n;i++){if(odd[i]==1)sum++;}cout<<sum;return 0; }

總結(jié)

以上是生活随笔為你收集整理的2020牛客国庆集训派对day3 Points的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。