#P7639. [BalticOI 2006] COUNTRIES (Day 1)

[BalticOI 2006] COUNTRIES (Day 1)

Description

Consider a 2D map of a region. There are nn cities on this map. Each city ii has a unique coordinate (xi,yi)(x_i, y_i). Each city has sis_i soldiers under the command of a general.

The intimidation (threat) that city ii exerts on another position (x,y)(x, y) equals sis_i divided by the square of the distance between it and (x,y)(x, y). You can think of it as the many soldiers in city ii exerting intimidation on all nearby positions on the map. If the intimidation from city jj to city ii at (xi,yi)(x_i, y_i) exceeds its number of soldiers sis_i (meaning city jj can send enough soldiers to subdue the soldiers defending city ii), then city ii is threatened by city jj. If city ii is not threatened by any other city jj, then the grateful citizens will elect their invincible general as their king, and make their city the capital of his kingdom.

On the other hand, if some city jj threatens city ii at (xi,yi)(x_i, y_i) more than another city kk does, then the residents of city ii have no choice: city ii can only surrender to city jj. From then on, city ii must obey the capital that city jj obeys; however, the soldiers of city ii do not join the army of city jj or its capital. In addition, city ii can be saved because two cities jj and kk that threaten it equally will guard against each other: if one city attacks and conquers city ii, the other will come to attack and defeat the attacker’s soldiers, who have just fought and are exhausted. But in this case, the residents of city ii will no longer elect their general as king, because he failed in his duty to protect the city from threats. Therefore, they must make their city the capital of a democratic country.

Your task is to write a program that takes the map’s city information as input, and for each city ii outputs one of the following three results:

  • It is the capital of a kingdom.
  • It is the capital of a democratic country.
  • It obeys city jj as its capital.

Input Format

The first line contains an integer nn, the number of cities. The next nn lines give the information of these nn cities. Line i+1i+1 contains three integers xix_i, yiy_i, sis_i describing city ii, separated by single spaces.

Output Format

Output consists of nn lines. Line ii contains the result for city ii:

  • The letter K\texttt{K} means city ii is the capital of a kingdom.
  • The letter D\texttt{D} means city ii is the capital of a democratic country.
  • A positive integer jj means city ii must surrender and obey city jj as its capital.
5
2 5 14
2 3 2
3 2 7
1 1 2
2 1 3
K
D
K
3
3

Hint

Constraints

For 100%100\% of the testdata, 1n10001 \le n \le 1000, 0xi,yi,si10000 \le x_i, y_i, s_i \le 1000, 1jn1 \le j \le n.

Sample Explanation

Consider the following map, where each point represents a city, and the number above it is the number of soldiers: TuLi
That is, city 33 at position (3,2)(3, 2) is the capital of a kingdom, and it also includes city 44 at position (1,1)(1, 1) and city 55 at position (2,1)(2, 1). On the other hand, city 11 at position (2,5)(2, 5) forms a kingdom by itself, and city 22 at position (2,3)(2, 3) forms a democratic country by itself.

Problem Notes

From Day 1: Countries of the Baltic Olympiad in Informatics 2006.
Translated and organized by @求学的企鹅.

Translated by ChatGPT 5