Codevs 1955 Optical Fiber Communication Usaco

Source: Internet
Author: User

1955 Optical Fiber Communication

Usaco

time limit: 1 sspace limit: 128000 KBtitle level: Golden GoldView Run ResultsTitle Description Description

Farmer John wants to connect his n (1 <= n <= 1,000) barn with fiber optics (ref. 1). N). However, barn is located on a large pond, where he can only connect to neighboring barns. John doesn't need to connect to all the barn, because only some cows want to communicate with each other. In keeping these cows in communication, he wanted to use the fewest fiber optics to complete the communication network component work. Give a list of the paired cows you want to communicate, and ask for the minimum number of fibers to be used.

Enter a description Input Description

Line 1th: 2 integers, N and p (number of cows wanting to communicate, 1<=p<=10,000)

2nd.. P+1:2 integers that describe the number of two cows you want to communicate

Output description Output Description

Only 1 lines, that is, the minimum number of fibers used.

Sample input Sample Input

5 2

1 3

4 5

Sample output Sample Output

3

Data range and Tips Data Size & Hint

Sample scenario: Connection 1-2, connection 2-3, connection 4-5

#include <iostream>#include<cstdio>#include<cstring>#defineMAXN 1010using namespacestd;intn,m,a[maxn*2][maxn*2],b[maxn*2],ans=0x7fffffff;intMain () {inti,j,k; scanf ("%d%d",&n,&m);  for(i=1; i<=m;i++)    {        intx, y; scanf ("%d%d",&x,&y); if(x>y) Swap (x, y); A[x][y]=1; A[y][x+n]=1; A[x+n][y+n]=1; }     for(i=1; i<=n;i++)//Enumerate Breakpoints{memset (b,0,sizeof(b)); inttot=0;//to make a breakpoint with I need to connect several sides         for(j=i;j<=i+n-1; j + +)//points within an enumeration interval        {             for(k=i+n-1; k>=j;k--)//from the big to the small enumeration, find the farthest point of J to connect.            if(A[j][k]) { for(intl=j;l<=k-1; l++)//See if L and l+1 are connected, not even tot++.                if(b[l]==0) {B[l]=1; Tot++; }                 Break;//find the furthest, the smaller, and you don't have to find it.}} ans=min (Ans,tot); } printf ("%d\n", ans); return 0;}

Codevs 1955 Optical Fiber Communication Usaco

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.