F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Chess Class

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 218    Accepted Submission(s): 82


Problem Description
This class is on chess. Baby Volcano is playing a special chess game with his friend, Baby Evil.

In this chess game, there is a directed graph $G = (V,E)$. Vertices are indexed from $1$ to $n$. It is guaranteed that every vertex has at least one out-going edge, i.e. $\forall v\in V, \exists w\in V, (v,w)\in E$, Baby Volcano takes control of a subset of vertices $X\subseteq V$, Baby Evil takes control of $V\setminus X$. Every vertex $v$ is assigned a weight $W(v)$.

There is a chess, positioning at $s\in V$ initially. The game consists of three phases.

1. For every $p\in X$, Baby Volcano chooses an out-going edge $(p,q)\in E$ and delete other out-going edges of vertex $p$.

2. After Volcano's operation, Baby Evil would similarly choose an out-going edge $(p',q')\in E$ and delete other out-going edges of $p'$ for every $p' \notin X$. Both two babies make decisions based on chess's initial position $s$.

3. After two processes above, every vertex would remain only one out-going edge. The chess starts moving along the unique path in the processed graph, resulting in an infinite path $L = v_0v_1v_2\cdots$, where $v_0=s$. Baby Volcano gains score $CV$ at last, which is computed below:
$$CV:= \max\left\{W\left(v_i\right) \ |\ v_i \text{ appears in }L\right\}$$

Baby Volcano wants to maximize $CV$, while Baby Evil wants to minimize it.

Your task is to determine, for every $s,1\leq s\leq n$, compute $CV$ under the circumstance that the chess is put at $s$ initially.
 

Input
In the first line there is a number $T$, denotes the number of test cases.

Then there are $T$ parts of input, each part describes a test case. Each parts begins with $n,m,R,B$, denotes the number of vertices, edges, the range of $W(v)$, and the size of $X$, the set which baby volcano takes control.

Then there is a line consists of $B$ numbers, denotes elements in $X$.

Then there is a line with $n$ numbers, the $i$-th number, denotes $W(i), 1\leq W(i)\leq R$.

Then there are $m$ lines, each line consists of $2$ numbers, $u,v$, showing that there is an edge from $u$ to $v$ in $G$.

$1\leq T\leq 100$

$1\leq m,R\leq 5\times 10^5$

$1\leq B\leq n\leq 5\times 10^5$

$1\leq \sum{n},\sum{m},\sum{R}\leq 10^6$
 

Output
For each test case, you should first output ''Case #t:''(without quotes), denotes the test number.

Then you need to output $n$ numbers in the next line, the $i$-th number is $CV$ under the circumstance that the chess is put at $i$ initially.
 

Sample Input
2 3 3 2 1 3 1 1 2 1 2 2 3 3 3 4 6 10 1 4 8 7 3 2 1 3 2 4 3 2 4 2 2 1 2 2
 

Sample Output
Case #1: 2 2 2 Case #2: 8 7 7 7
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-09 05:23:54, Gzip enabled