codeforces-scrape

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

1609D.md (2669B)


      1 Source: https://codeforces.com/problemset/problem/1609/D
      2 
      3 D. Social Network
      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 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 ![](https://espresso.codeforces.com/c43f6bdabab64957bbed2ebb101fcf642a19ed6c.png) 
     22 
     23 William arrived at a conference dedicated to cryptocurrencies. Networking, meeting new people, and using friends' connections are essential to stay up to date with the latest news from the world of cryptocurrencies.
     24 
     25 The conference has $n$ participants, who are initially unfamiliar with each other. William can introduce any two people, $a$ and $b$, who were not familiar before, to each other.
     26 
     27 William has $d$ conditions, $i$'th of which requires person $x_i$ to have a connection to person $y_i$. Formally, two people $x$ and $y$ have a connection if there is such a chain $p_1=x, p_2, p_3, \dots, p_k=y$ for which for all $i$ from $1$ to $k - 1$ it's true that two people with numbers $p_i$ and $p_{i + 1}$ know each other.
     28 
     29 For every $i$ ($1 \le i \le d$) William wants you to calculate the maximal number of acquaintances one person can have, assuming that William satisfied all conditions from $1$ and up to and including $i$ and performed exactly $i$ introductions. The conditions are being checked after William performed $i$ introductions. The answer for each $i$ must be calculated independently. It means that when you compute an answer for $i$, you should assume that no two people have been introduced to each other yet.
     30 
     31 Input
     32 
     33 The first line contains two integers $n$ and $d$ ($2 \le n \le 10^3, 1 \le d \le n - 1$), the number of people, and number of conditions, respectively.
     34 
     35 Each of the next $d$ lines each contain two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n, x_i \neq y_i$), the numbers of people which must have a connection according to condition $i$.
     36 
     37 Output
     38 
     39 Output $d$ integers. $i$th number must equal the number of acquaintances the person with the maximal possible acquaintances will have, if William performed $i$ introductions and satisfied the first $i$ conditions.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 7 6
     47 1 2
     48 3 4
     49 2 4
     50 7 6
     51 6 5
     52 1 7
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 1
     59 1
     60 3
     61 3
     62 3
     63 6
     64 ```
     65 
     66 Input
     67 
     68 ```
     69 10 8
     70 1 2
     71 2 3
     72 3 4
     73 1 4
     74 6 7
     75 8 9
     76 8 10
     77 1 4
     78 ```
     79 
     80 Output
     81 
     82 ```
     83 1
     84 2
     85 3
     86 4
     87 5
     88 5
     89 6
     90 8
     91 ```
     92 
     93 Note
     94 
     95 The explanation for the first test case:
     96 
     97 In this explanation, the circles and the numbers in them denote a person with the corresponding number. The line denotes that William introduced two connected people. The person marked with red has the most acquaintances. These are not the only correct ways to introduce people.
     98 
     99  ![](https://espresso.codeforces.com/0c014d3a638835c213347a0ecd6726618aba50b3.png)