您的位置:首页 > 理论基础 > 计算机网络

[河南省ACM省赛-第三届] 网络的可靠性 (nyoj 170)

2015-04-02 08:46 369 查看
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=170

根据题意,需要找到度数为1的结点个数,如下图:





#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
#define N 10002

vector<int> g
;

int main()
{
freopen("d:\\in.txt", "r", stdin);
int n;
while(~scanf("%d", &n)) {
int a, b;
for(int i=0; i<n+2; i++){
g[i].clear();
}
for(int i=0; i<n-1; i++){
scanf("%d%d", &a, &b);
g[a].push_back(b);
g[b].push_back(a);
}
int tot = 0;//度为1的个数
for(int i=1; i<=n; i++){
if(g[i].size() == 1)
tot++;
}
printf("%d\n", (tot+1)/2);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: