Network Reliability of nyoj 170

Source: Internet
Author: User
Network ReliabilityTime Limit: 3000 MS | memory limit: 65535 kb difficulty: 3
Description

Company A is a global Internet solution provider and a senior sponsor of the 2010 World Expo. It will provide advanced network collaboration technologies to demonstrate its "smart + interconnected" concept of life, while providing visitors with high-quality personal experience and interaction, with "Information Communication, enjoy the city dream as the theme. With the help of Fantastic theater screens and special effects, we can present the application prospects of information and communication technology. With vivid stories, we can present an unlimited future social outlook for communication to the audience.

To this end, Company A has established a Video Communication System for N regions of the World Expo Park. Each region has a base station numbered 1, 2, 3..., n. Video services are provided to visitors in various regions through communication lines between base stations.

It is known that some optical fiber communication lines have been laid between the base stations. These lines cover all regions, I .e., video transmission can be performed in either region. However, in order to save costs, only N-1 lines are currently laid, and in order to reduce the information transfer load of each base station, each base station can have up to three optical fiber communication lines connected with it.

However, during the trial run of the communication system, Company A found that when a base station fails, information could not be transmitted between other regions. To improve the reliability of the communication network, Company A is preparing to lay some new optical fiber lines between the base stations, so that after any base station fails, other base stations can still communicate with each other.

Due to the expensive cost of laying lines, Company A hopes that the fewer new optical fiber lines, the better. Company A requested dr. Kong to complete this task.

 
Input
There are multiple groups of test data, ending with EOF.
Line 1: N indicates that there are n Base Stations
Next there is a N-1 line: x y indicates that the x base station is directly connected to the Y Base Station
1 <= n <= 10000
Output
Returns an integer indicating at least the number of new optical fiber cables.
Sample Input
81 33 25 35 4 5 62 72 8
Sample output
3
Source
Third Henan Program Design Competition
Uploaded
Zhang yuncong

Problem solving: undirected graph. If the degree is 1, it is definitely not safe. Count the number of base stations with a level of 1 and divide the number by 2. rounded up.

 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <vector> 6 #include <climits> 7 #include <algorithm> 8 #include <cmath> 9 #define LL long long10 #define INF 0x3f3f3f11 using namespace std;12 int main(){13     int cnt[10010],i,sum,n,u,v;14     while(~scanf("%d",&n)){15         memset(cnt,0,sizeof(cnt));16         for(i = 1; i < n; i++){17             scanf("%d%d",&u,&v);18             cnt[u]++;19             cnt[v]++;20         }21         sum = 0;22         for(i = 1; i <= n; i++){23             if(cnt[i] == 1) sum++;24         }25         printf("%d\n",(sum+1)>>1);26     }27     return 0;28 }
View code

 

 

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.