codeforces-scrape

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

954D.md (2254B)


      1 Source: https://codeforces.com/problemset/problem/954/D
      2 
      3 D. Fight Against Traffic
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Little town Nsk consists of *n* junctions connected by *m* bidirectional roads. Each road connects two distinct junctions and no two roads connect the same pair of junctions. It is possible to get from any junction to any other junction by these roads. The distance between two junctions is equal to the minimum possible number of roads on a path between them.
     22 
     23 In order to improve the transportation system, the city council asks mayor to build one new road. The problem is that the mayor has just bought a wonderful new car and he really enjoys a ride from his home, located near junction *s* to work located near junction *t*. Thus, he wants to build a new road in such a way that the distance between these two junctions won't decrease.
     24 
     25 You are assigned a task to compute the number of pairs of junctions that are not connected by the road, such that if the new road between these two junctions is built the distance between *s* and *t* won't decrease.
     26 
     27 Input
     28 
     29 The firt line of the input contains integers *n*, *m*, *s* and *t* (2 ≤ *n* ≤ 1000, 1 ≤ *m* ≤ 1000, 1 ≤ *s*, *t* ≤ *n*, *s* ≠ *t*) — the number of junctions and the number of roads in Nsk, as well as the indices of junctions where mayors home and work are located respectively. The *i*-th of the following *m* lines contains two integers *u**i* and *v**i* (1 ≤ *u**i*, *v**i* ≤ *n*, *u**i* ≠ *v**i*), meaning that this road connects junctions *u**i* and *v**i* directly. It is guaranteed that there is a path between any two junctions and no two roads connect the same pair of junctions.
     30 
     31 Output
     32 
     33 Print one integer — the number of pairs of junctions not connected by a direct road, such that building a road between these two junctions won't decrease the distance between junctions *s* and *t*.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 5 4 1 5  
     41 1 2  
     42 2 3  
     43 3 4  
     44 4 5
     45 ```
     46 
     47 Output
     48 
     49 ```
     50 0
     51 ```
     52 
     53 Input
     54 
     55 ```
     56 5 4 3 5  
     57 1 2  
     58 2 3  
     59 3 4  
     60 4 5
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 5
     67 ```
     68 
     69 Input
     70 
     71 ```
     72 5 6 1 5  
     73 1 2  
     74 1 3  
     75 1 4  
     76 4 5  
     77 3 5  
     78 2 5
     79 ```
     80 
     81 Output
     82 
     83 ```
     84 3
     85 ```