#P5786. [CQOI2008] 传感器网络
[CQOI2008] 传感器网络
Description
A wireless sensor network consists of several devices that collect data independently and a control center. Each device must send the collected data to the control center for processing, but due to device limitations, not every device can connect directly to the control center. To solve this, you design the sensor network as a tree structure. The root of the tree is the control center, and each device has exactly one parent node (either the control center or another device). The number of child devices of a device is called its load level. The maximum load level among all devices (note that the control center is not a device) is called the network load level.
Your task is to make the network load level as small as possible.
Input Format
The first line contains an integer , the number of devices. The second line contains characters, indicating whether each device can connect directly to the control center. The next lines each contain characters, where the -th character in the -th line is Y if and only if device can be a child of device . If device can be a child of device , then in any valid network, device will definitely not be a descendant of device . In other words, if you treat these lines as the adjacency matrix of a directed graph, the graph has no directed cycles.
Output Format
Output exactly one line containing integers, the parent of each device. Devices are numbered from to in input order, and the control center is denoted by . If there are multiple solutions, output the lexicographically smallest one.
5
YNNYN
NNNNN
YNNNY
NNNYN
NNNNN
YNNYN
5 4 3 5 0
Hint

For of the testdata, ; for the other of the testdata, .
Constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号