(Challenge) SnackDown 99

All submissions for this problem are available.
### Read problem statements in [Hindi](http://www.codechef.com/download/translated/JUNE19/hindi/SNCK99.pdf), [Bengali](http://www.codechef.com/download/translated/JUNE19/bengali/SNCK99.pdf), [Mandarin Chinese](http://www.codechef.com/download/translated/JUNE19/mandarin/SNCK99.pdf), [Russian](http://www.codechef.com/download/translated/JUNE19/russian/SNCK99.pdf), and [Vietnamese](http://www.codechef.com/download/translated/JUNE19/vietnamese/SNCK99.pdf) as well. **This is an interactive problem.** SnackDown 2099 will take part in the ChefLand International Office (CIO). Ada is in charge of preparation of the coding environment. Ada prepared $N$ computer terminals (numbered $1$ through $N$) interconnected by $M$ bidirectional networking cables (numbered $1$ through $M$). Each of the cables connects two different terminals and no two different cables connect the same pair of terminals. Let's denote a cable between terminals $u$ and $v$ by $(u, v)$. At the contest site, there should be some guards that make sure everything runs smoothly. During the competition, each terminal is assigned either to a contestant or to a guard; note that the number of contestants is not fixed yet. Ada assigns a *stability* to each terminal. Let's denote the stability of terminal $i$ by $S_i$. Also, let's denote the cost of removing cable $i$ by $W_i$. Since there are many cables, the room is messy, so Ada decided to remove some of the cables (possibly none or all of them) one by one. However, after removing any cable, the stability of some terminal or the cost of removing some cable might change. Ada thinks that it is dangerous to have cables directly connect terminals assigned to contestants (they could try to team up and share solutions!). To measure the danger of such a situation, she defined $D_C$ as the sum of $S_u \cdot S_v$ over all remaining cables $(u, v)$ such that the terminals $u$ and $v$ are both assigned to contestants. Similarly, Ada thinks that it is dangerous to have cables directly connect terminals assigned to guards (they could start chatting and get distracted!). To measure the danger of this situation, she defined $D_G$ similarly to $D_C$, as the sum of $S_u \cdot S_v$ over all remaining cables $(u, v)$ such that the terminals $u$ and $v$ are both assigned to guards. Let's denote the total cost of removing cables (sum of costs for all removed cables when they were removed) by $X$. Ada wants to minimise $X+D_C+D_G$. Help her prepare the coding environment! Specifically, choose some cables to remove and then assign the terminals to contestants or guards in such a way that $X+D_C+D_G$ is as small as possible. ### Interaction  First, you should read $3+M$ lines describing the original network configuration.  The first of these lines contains two spaceseparated integers $N$ and $M$.  The second line contains $N$ spaceseparated integers $S_1, S_2, \ldots, S_N$ denoting the initial stabilities of the terminals.  The third line contains $M$ spaceseparated integers $W_1, W_2, \ldots, W_M$ denoting the initial costs of removing cables.  Each of the next $M$ lines contains two spaceseparated integers $u$ and $v$ denoting that terminals $u$ and $v$ are connected by a networking cable.  Then, you should remove cables.  To remove a cable, you should print a line containing a single integer $w$ ($1 \le w \le M$) denoting the number of the cable you want to remove. You must not attempt to remove the same cable twice.  Then, you should read a line describing any changes in the stabilities or costs after this cable is removed, in one of the following formats:  `0 i x` ($1 \le i \le N$) denoting that the new value of $S_i$ is $x$  `1 i y` ($1 \le i \le M$) denoting that the new value of $W_i$ is $y$  `2` denoting that the stabilities and costs did not change  When you do not want to remove any more cables, you must print a line containing the integer $1$.  Finally, you must print a line containing a single string with length $N$. For each valid $i$, the $i$th character of this string should be 'C' if the $i$th terminal is assigned to a contestant or 'G' if it is assigned to a guard. If your output is invalid or you attempt to remove a cable multiple times, you will receive the Wrong Answer verdict. Don't forget to flush the output after printing each line! ### Constraints  $1 \le N \le 2^9$  $0 \le M \le N(N1)/2$  $1 \le u, v \le N$  $1 \le S_i \le 2^{10}$ for each valid $i$  $1 \le W_i \le 2^{17}$ for each valid $i$  $1 \le x \le 2^{10}$  $1 \le y \le 2^{17}$ ### Example ``` Grader You 4 6 1 2 3 4 1 2 3 4 5 6 1 2 2 3 3 4 4 1 2 4 1 3 3 0 1 2 4 1 2 3 1 CCGG ``` ### Explanation ### Scoring The score of each test case (and therefore each test file) is $X+D_C+D_G$. The score of a submission is the sum of scores of all test files. Your goal is to minimise the score of your submission. There are twenty test files. During the contest, the displayed score will account for exactly four test files, i.e. your score reflects your submission's performance on 20% (4/20) of the test files. However, if your program gets a nonAC verdict on any test file, your submission's verdict will be nonAC. In other words, an AC verdict denotes that your program runs successfully on all the test files. After the end of the contest, your score will be changed to include the sum of your program's scores over the other sixteen test files. ### Test generation The grader is given probabilities $p_v$, $p_w$, and three numbers $MX_S$, $MN_W$ and $MX_W$. For all test cases, $N = 512$ and $MX_S = 1024$. There are three types of networks:  Complete: There is a cable between each pair of terminals.  Hamiltonian: There is a sequence of terminals $a_1, a_2, \ldots, a_N$ such that there is a cable between terminals $a_i$ and $a_{i+1}$ for each valid $i$ and a cable between terminals $a_N$ and $a_1$. The number of cables in this network is approximately $N (N1) / 5$.  Special networks. The stabilities are generated uniformly randomly between $1$ and $MX_S$ inclusive and the removal costs are generated uniformly randomly between $MN_W$ and $MX_W$ inclusive. Whenever you remove a cable, the grader decides to modify the stability of some terminal with probability $p_v$, the cost of removing some cable with probability $p_w$, or to do nothing (with probability $1p_vp_w$). The stabilities and removal costs are changed using one of the following strategies:  Pure Random:  Stabilities: Choose a terminal uniformly randomly and change its stability to a random integer between $1$ and $MX_S$.  Removal costs: Uniformly randomly choose a cable that has not been removed yet and change its removal cost to a random integer between $1$ and $MX_W$.  Shrink:  Stabilities: Choose a terminal uniformly randomly and change its stability to a random number between $1$ and $MX_S$.  Removal costs: Let $c_0, c_1, \ldots, c_{m1}$ be the cables that are still in the network, sorted first by their current removal costs and then by their indices. Generate a uniformly random number $d$ between $0$ and $99$ inclusive and choose a cable $c_r$ uniformly randomly. Let $X$ be the current cost of removing $c_r$.  If $2 \cdot r \le m$, then the new cost of removing cable $c_r$ will be $\mathrm{min}\,(X+d, MX_W)$.  Otherwise, the new cost of removing this cable will be $\mathrm{max}(Xd, 1)$.  Adaptative:  Let $r$ be the index of the cable you just decided to remove.  Stabilities: Choose one of the terminals connected by $r$ uniformly randomly. Let $X$ denote the current stability of that terminal. Generate a uniformly random number $d$ between $0$ and $19$.  With probability $0.3$, the new stability of this terminal will be $\mathrm{min}\,(X+d, MX_S)$.  With probability $0.7$, the new stability of this terminal will be $\mathrm{max}\,(Xd, 1)$.  Removal costs: Let $c$ be the smallest index of a cable such that it has not been removed yet and its removal cost is greater or equal to the cost of removing cable $r$. If no such cable exists, then $c$ is the largest index of a cable with maximum removal cost (that has not been removed yet). Change the removal cost of cable $c$ to a uniformly random integer between $1$ and $MX_W$. Network type p_v p_w MN_W MX_WComplete  0.05  0.05  1  2^{17} 
Complete  0.4  0.4  1  2^{17} 
Complete  0.05  0.05  2^{16}  2^{16} + 100 
Hamiltonian  0.05  0.05  1  2^{17} 
Hamiltonian  0.4  0.4  1  2^{17} 
Special  0.05  0.05  1  2^{17} 
Special  0.4  0.4  2^{16}  2^{16} + 100 
Author:  alei 
Tags  alei 
Date Added:  24052019 
Time Limit:  4 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 