COGS8 Standby switch

Source: Internet
Author: User

Standby switch

★ Import File: gd.in output file: gd.out Simple comparison
Time limit: 1 s memory limit: MB

"Problem description"

There is a communication network between n cities, and each city has a communication switch that connects directly or indirectly with other cities. Because electronic devices are prone to damage, the communication points need to be equipped with backup switches. However, the number of spare switches is limited and can not be fully equipped, but only for some important city configurations. Accordingly: If a city because of the switch damage, not only the city communication is interrupted, but also caused other city communication interruption, then equipped with standby switch. Please calculate the number of cities that need to be equipped with backup switches and the number of cities to be equipped with alternate switches, depending on the city line situation. The input format input file has several lines
First line, an integer n, representing a total of n cities (2<=n<=100)
There are several lines below, each line 2 number A, b,a, B is the city number, indicating A and B have a direct communication line. "Output format" output file has several lines
The first line, 1 integer m, indicates that a m standby switch is required, with m lines below, each line having an integer indicating the city number to be equipped with the switch, and the output sequence numbered from small to large. Output 0 if no city needs to be equipped with a standby switch. "Input and Output sample"

Input file name: gd.in

7

1 2

2 3

2 4

3 4

4 5

4 6

4 7

5 6

6 7

Output file name: Gd.out

2

2

4

Cut the dots.

Note that the number of read-in roads is not equal to n

1 /*by Silvern*/2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <vector>8 using namespacestd;9 Const intmxn=20000;Ten Const intmxm= -; Onevector<int>E[MXN]; A intGD[MXM]; - intN; - intRoot,dtime=0; the intDFN[MXM],LOW[MXM]; - intans=0; -  - voidAdd_edge (intUintv) { + E[u].push_back (v); - e[v].push_back (u); +     return; A } at voidTarjan (intu) { -     inti; -     inttot=0; -low[u]=dfn[u]=++Dtime; -     intv; -      for(i=0; I<e[u].size (); i++){ inv=E[u][i]; -         if(!Dfn[v]) { to Tarjan (v); +++tot; -low[u]=min (low[v],low[u]); the             if((U==root && tot>1)|| (U!=root && low[v]>=Dfn[u])) *                 if(!gd[u]) gd[u]=true, ans++; $         }Panax Notoginseng         Elselow[u]=min (low[u],dfn[v]); -     } the     return; + } A intMain () { theFreopen ("gd.in","R", stdin); +Freopen ("Gd.out","W", stdout); -scanf"%d",&n); $     inti,j; $     intb; -      while(SCANF ("%d%d", &a,&b)! =EOF) - Add_edge (A, b); the      for(i=1; i<=n;i++){ -         if(!Dfn[i]) {Wuyiroot=i; the Tarjan (i); -         } Wu     } -printf"%d\n", ans); About      for(i=1; i<=n;i++){ $         if(Gd[i]) printf ("%d\n", i); -     } -     return 0; -}

COGS8 Standby switch

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.