codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

292B.md (3310B)


      1 Source: https://codeforces.com/problemset/problem/292/B
      2 
      3 B. Network Topology
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
     22 
     23 Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of *n* computers, some of them are connected by a cable. The computers are indexed by integers from 1 to *n*. It's known that any two computers connected by cable directly or through other computers
     24 
     25 Polycarpus decided to find out the network's topology. A network topology is the way of describing the network configuration, the scheme that shows the location and the connections of network devices.
     26 
     27 Polycarpus knows three main network topologies: bus, ring and star. A bus is the topology that represents a shared cable with all computers connected with it. In the ring topology the cable connects each computer only with two other ones. A star is the topology where all computers of a network are connected to the single central node.
     28 
     29 Let's represent each of these network topologies as a connected non-directed graph. A bus is a connected graph that is the only path, that is, the graph where all nodes are connected with two other ones except for some two nodes that are the beginning and the end of the path. A ring is a connected graph, where all nodes are connected with two other ones. A star is a connected graph, where a single central node is singled out and connected with all other nodes. For clarifications, see the picture.
     30 
     31  ![](https://espresso.codeforces.com/6b81abd310d29da96807c0661ba93805e9a59cde.png) (1) — bus, (2) — ring, (3) — star 
     32 
     33 You've got a connected non-directed graph that characterizes the computer network in Polycarpus' corporation. Help him find out, which topology type the given network is. If that is impossible to do, say that the network's topology is unknown.
     34 
     35 Input
     36 
     37 The first line contains two space-separated integers *n* and *m* (4 ≤ *n* ≤ 105; 3 ≤ *m* ≤ 105) — the number of nodes and edges in the graph, correspondingly. Next *m* lines contain the description of the graph's edges. The *i*-th line contains a space-separated pair of integers *x**i*, *y**i* (1 ≤ *x**i*, *y**i* ≤ *n*) — the numbers of nodes that are connected by the *i*-the edge.
     38 
     39 It is guaranteed that the given graph is connected. There is at most one edge between any two nodes. No edge connects a node with itself.
     40 
     41 Output
     42 
     43 In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topology" (without the quotes).
     44 
     45 Examples
     46 
     47 Input
     48 
     49 ```
     50 4 3  
     51 1 2  
     52 2 3  
     53 3 4
     54 ```
     55 
     56 Output
     57 
     58 ```
     59 bus topology
     60 ```
     61 
     62 Input
     63 
     64 ```
     65 4 4  
     66 1 2  
     67 2 3  
     68 3 4  
     69 4 1
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 ring topology
     76 ```
     77 
     78 Input
     79 
     80 ```
     81 4 3  
     82 1 2  
     83 1 3  
     84 1 4
     85 ```
     86 
     87 Output
     88 
     89 ```
     90 star topology
     91 ```
     92 
     93 Input
     94 
     95 ```
     96 4 4  
     97 1 2  
     98 2 3  
     99 3 1  
    100 1 4
    101 ```
    102 
    103 Output
    104 
    105 ```
    106 unknown topology
    107 ```