luogu#P5085. 大奔的方案

大奔的方案

Background

Solution: https://blog.csdn.net/kkkksc03/article/details/83188325.

Five pirates have seized 100100 gold coins, each of the same size and extremely valuable.

They decide to distribute them as follows:

  1. Draw lots to decide their numbers [1,2,3,4,5][1, 2, 3, 4, 5].
  2. First, pirate 11 proposes a distribution plan. Then all 55 pirates vote. If and only if no fewer than half of them agree, the distribution is carried out according to his proposal; otherwise, he will be thrown into the sea to feed the sharks.
  3. If pirate 11 dies, then pirate 22 proposes a distribution plan. Then all 44 remaining pirates vote. If and only if no fewer than half of them agree, the distribution is carried out according to his proposal; otherwise, he will be thrown into the sea to feed the sharks.
  4. And so on...

Each pirate is very smart and follows these rules:

  1. Stay alive.
  2. If rule 11 is satisfied, try to get as many coins as possible.
  3. If rules 1,21, 2 are satisfied, try to kill as many people as possible.

So what will the final distribution plan be?

The pirates ask Xiao Ben to compute: if there are NN pirates who seized MM gold coins, and at least P%P\% of the voters must vote in favor, how will they distribute the coins?

Please give a method for NN pirates to split MM coins with at least P%P\% votes in favor, and ensure that pirates with smaller numbers receive as many coins as possible.

However, in reality it will not be so cruel. Each pirate also has their own gang, and people in the same gang will vote in favor of each other.

As the price of friendship, the proposer must give every other person in their gang a certain number of coins. If any one person (excluding the proposer themself) is not satisfied, then everyone in that gang will vote against at the same time.

What will the new result be?

Problem Description

If A and B are friends, and B and C are also friends, then A, B, and C are all in the same gang.

Now you are given xx brotherhood relations. Please determine the gang relationships, and then find the new method for nn pirates to split mm coins.

Warning: toxic problem.

Of course, you still need to ensure that pirates with smaller numbers receive as many coins as possible, even if it breaks relationships between gangs. (Figure it out yourself.)

Input Format

The first line contains five integers n,m,p,x,kn, m, p, x, k separated by spaces, representing the number of pirates, the number of coins, the minimum approval percentage, the total number of brotherhood relations, and the so-called friendship cost.

The next XX lines each contain two integers i,ji, j, meaning ii and jj have a brotherhood relation (that is, they are in the same gang).

Output Format

Only one line containing NN integers separated by spaces, representing the final result.

If a pirate dies, output 1-1 instead.

5 7 50 2 1
1 2
3 2
5 1 1 0 0

Hint

Constraints and Notes

For 100%100\% of the testdata: 1n10001\le n\le 1000, 0m1050\le m\le 10^5, 1p1001\le p\le 100, 1x5001\le x\le 500, 1k1001\le k\le 100.

Translated by ChatGPT 5