nyoj170 Network Reliability (the third Henan Province Program design Competition)

Source: Internet
Author: User

    • The topic of the
    • topic information
    • run result
    • line
    • discussion area
Network Reliability time limit: theMs | Memory Limit:65535KB Difficulty:3
Describe

Company A is a global provider of Internet Solutions and a senior sponsor of the 2010 World Expo. It will provide advanced network collaboration technology to showcase its "smart + connected" concept of life, while providing visitors with high-quality personal experience and interaction, "information and communication, urban Dream" as the theme throughout. With the help of the fantastic theatrical screens and special effects, the application of ICT is presented, and through vivid stories, the audience is presented with unlimited future social prospects.

For this reason, company A has established a video communication system for the N regions of the Expo Park, each of which establishes a base station, numbered sequentially 1,2,3...,n. Video services are provided for visitors to each region through the communication lines between the base stations.

It is known that a number of fiber optic communication lines have been installed between the base stations, which cover all areas, that is, any two zones are capable of video transmission. But in order to save cost, currently only N-1 line is laid, and in order to reduce the information transmission load of each base station, there are up to three fiber optic communication lines connected with each base station.

However, during the trial operation of the communication system, a company discovered that when a base station fails, it can cause the transmission of information between other regions. In order to improve the reliability of the communication network, a company is prepared to lay a new number of fiber optic lines between the base station, so that any one base station failure, the other base stations can still communicate.

As the cost of laying lines is expensive, company a hopes that the new fiber-optic lines will be as few as possible. A company request Dr. Kong to complete this mission.

Input
There are multiple sets of test data, with EOF as the end flag.
First line: n means there are n base stations
Next there are N-1 lines: x y indicates that the X base Station and the Y base station are connected directly
1<=n<=10000
Output
outputs an integer that indicates the minimum number of new fibre lines to be laid
Sample input
81 33 25 35 4 5 62 72 8
Sample output
3
Source
The
third Henan Province Program design Competition
Uploaded by
Zhang Yunzun

You can judge the degree of the vertex. If only 1 are sure to add a line to it to meet test instructions. Otherwise, only one, if it's bad, it's bad.

Since it is as small as possible, if there are two fixed point of the degree is 1, of course, let them connect together best but 0.0 ....

All in all, the problem is not too complicated, since you say if a vertex is broken (you know it), but also want to be able to connect him, that is to say, there is at least one line connected to it.

So the problem is to find the number of vertices with a degree of 1. If the even number is divided by 2, if it is an odd number, divide by 2 to have a connection outside so again +1.

Code:

#include <stdio.h> #include <string.h>int main () {int n,num[10005];while (scanf ("%d", &n)!=eof) {memset (num,0,sizeof (num)); for (int i=0;i<n-1;i++) {int a,b;scanf ("%d%d", &a,&b); num[a]++,num[b]++;} int count=0;for (int i=1;i<=n;i++) if (num[i]==1) count++;p rintf ("%d\n", (count+1)/2);} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

nyoj170 Network Reliability (the third Henan Province Program design Competition)

Related Article

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.