A wireless sensor network consists of several independent measuring devices and one control center. Each device must be able to send its sensor readings to the control center, but due to limitations in range, not all of the devices can communicate directly with the control center. To solve this problem, each device is assigned a single parent to which it is capable of directly transmitting data. A parent can be either another device or the control center. Each device receives readings from all its children (if it has any), adds its own readings, and passes everything to its parent. All the readings must eventually reach the control center. The number of children a device has is called the device's burden level. The burden level of the entire network is the maximum burden level among all its devices. Note that the control center is not a device.
You are given a String network, where the j-th character of the i-th element is equal to 'Y' if the i-th device can directly transmit data to the j-th device, and 'N' otherwise. A wireless sensor network in this problem always represents a directed acyclic graph, so if device d1 can transmit data directly or indirectly to device d2, then device d2 can't transmit data directly or indirectly to device d1.
You are also given a String nearest, the i-th character of which is 'Y' if the i-th device can communicate directly with the control center, and 'N' otherwise. You must assign a parent to each device in a way that minimizes the burden level of the entire network. Return a int, the i-th element of which is the parent assigned to the i-th device. If the parent is another device, the i-th element must be the 0-based index of the parent device. If the parent is the control center, the i-th element must be n, where n is the number of devices in the network. If there are multiple possible return values, return the one among them that comes first lexicographically. If it is not possible to assign parents in such a way that the control center can receive all the devices' readings, return an empty int.