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

Difference of Languages

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 817    Accepted Submission(s): 230


Problem Description
A regular language can be represented as a deterministic finite automaton (DFA). A DFA contains a finite set of states $Q$ and a finite set of input symbols called the alphabet $¦²$. Initially, the DFA is positioned at the start state $q_0¡ÊQ$. Given the transition function $¦Ä(q,a)$ and an input symbol a, the DFA transit to state $¦Ä(q,a)$ if its current state is $q$.
Let $w=a_1 a_2¡­a_n$ be a string over the alphabet $¦²$. According to the above definition, the DFA transits through the following sequence of states.
$$q_0,q_1=¦Ä(q_0,a_1 ),q_2=¦Ä(q_1,a_2 ),¡­,q_n=¦Ä(q_{n-1},a_n )$$
The DFA also contains a set of accept states $F\subseteq Q$. If the last state $q_n$ is an accept state, we say that the DFA accepts the string $w$. The set of accepted strings is referred as the language that the DFA represents.
You are given two DFAs, and the languages that they represent may be different. You want to find the difference between the two languages. Specifically, you are trying to find a string that is accepted by one DFA but not accepted by the other DFA. As there could be multiple such strings, you only want the shortest one. If there are still multiple such strings, you would like the smallest one in lexicographical order.

 

Input
The first line of input contains a number $T$ indicating the number of test cases ($T¡Ü200$).
Each test case contains the description of two DFAs.
For the first DFA, the first line contains three integers $N$, $M$, and $K$, indicating the number of states, the number of rules describing the transition function, and the number of accept states ($1¡ÜK¡ÜN¡Ü1000,0¡ÜM¡Ü26N$). The states are numbered from 0 to $N ¨C 1$. The start state is always 0.
The second line contains $K$ integers representing the accept states. All these numbers are distinct.
Each of the next $M$ lines consists of two states $p$ and $q$, and an input symbol $a$, which means that the DFA transits from $p$ to $q$ when it receives the symbol $a$. You may assume that the alphabet in consideration consists of the 26 lowercase letters (a-z). It is guaranteed that, given $p$ and $a$, the next state $q$ is unique.
The description of the second DFA follows the same format as the above.
 

Output
For each test case, output a single line consisting of ¡°Case #X: Y¡±. $X$ is the test case number starting from 1. $Y$ is the shortest string that is accepted by one DFA but not accepted by the other DFA. If no such string exists, output the digit ¡°0¡± instead. Note that an empty string is also considered a string.
 

Sample Input
2 3 3 1 2 0 1 a 1 2 b 2 0 c 4 4 1 3 0 1 a 1 2 b 2 3 c 3 0 a 3 3 1 2 0 1 a 1 2 b 2 0 c 3 4 1 2 0 1 a 1 2 b 1 2 c 2 0 c
 

Sample Output
Case #1: ab Case #2: ac
 

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-04-20 06:06:11, Gzip enabled