Under construction

Still being built. Things may change

Kripke Model

Time limit1sMemory limit128 MB

Summary
Given a Kripke model with n up to 10000 states, compute the set of states satisfying the CTL formula E(x U (AG y)) using fixed-point graph algorithms.
Level

Medium7 of 10

Topics
Graph, DFS, Recursion, Implementation
Solved
No attempts yet

Problem

Testing and quality assurance are very time-consuming stages of the software development process. Various techniques are used to reduce the cost and time these stages consume. One such technique is software verification. Model checking is an approach to software verification based on Kripke models.

A Kripke model is a 5-tuple (P,S,S0,R,L)(P, S, S_0, R, L), where PP is a finite set of atomic propositions, SS is a finite set of states, S0⊂SS_0 \subset S is a set of initial states, R⊂S×SR \subset S \times S is a transition relation, and L⊂S×PL \subset S \times P is a truth relation. In this problem we ignore initial states, and RR is reflexive, so R(s,s)R(s, s) holds for every state s∈Ss \in S.

A path π\pi beginning in state ss is an infinite sequence of states s0s1…s_0 s_1 \ldots such that s0=ss_0 = s and (si,si+1)∈R(s_i, s_{i+1}) \in R for every i≥0i \ge 0.

Temporal logic and its subset Computation Tree Logic (CTL) describe propositions qualified in terms of time. Kripke models are often used to check properties described in CTL.

There are two kinds of CTL formulae: state formulae and path formulae, evaluated over states and paths respectively.

If p∈Pp \in P, then pp is a state formula that holds in state ss iff (s,p)∈L(s, p) \in L.

If ff is a path formula, then Af\mathrm{\mathbf{A}} f and Ef\mathrm{\mathbf{E}} f are state formulae, where A\mathrm{\mathbf{A}} and E\mathrm{\mathbf{E}} are path quantifiers:

  • Af\mathrm{\mathbf{A}} f holds in state ss iff ff holds for every path beginning in ss;
  • Ef\mathrm{\mathbf{E}} f holds in state ss iff there exists a path π\pi beginning in ss for which ff holds.

If ff and gg are state formulae, then Gf\mathrm{\mathbf{G}} f and fUgf \mathrm{\mathbf{U}} g are path formulae, where G\mathrm{\mathbf{G}} and U\mathrm{\mathbf{U}} are temporal operators:

  • Gf\mathrm{\mathbf{G}} f (Globally) holds for a path π=s0s1…\pi = s_0 s_1 \ldots iff ff holds in state sis_i for every i≥0i \ge 0;
  • fUgf \mathrm{\mathbf{U}} g (Until) holds for a path π=s0s1…\pi = s_0 s_1 \ldots iff there exists i≥0i \ge 0 such that gg holds in state sis_i and ff holds in every state s0,s1,…,si−1s_0, s_1, \ldots, s_{i-1}.

To verify a property described by a state formula ff means to find every state in which ff holds. Verifying an arbitrary property is quite complex. Your task is easier: write a program that verifies the property described by the temporal-logic formula E(xU(AGy))\mathrm{\mathbf{E}}(x \mathrm{\mathbf{U}} (\mathrm{\mathbf{A}} \mathrm{\mathbf{G}} y)), where xx and yy are atomic propositions.

Input

The first line contains three positive integers nn, mm, and kk — the number of states, transitions, and atomic propositions (1≤n≤10 0001 \le n \le 10\,000; 0≤m≤100 0000 \le m \le 100\,000; 1≤k≤261 \le k \le 26).

Each of the next nn lines describes one state. State ii (1≤i≤n1 \le i \le n) is described by cic_i — the number of atomic propositions that are true in this state — followed by a space-separated list of those propositions (0≤ci≤k0 \le c_i \le k). Atomic propositions are denoted by the first kk lowercase English letters.

Each of the next mm lines describes one transition and contains two integers ss and tt (1≤s,t≤n1 \le s, t \le n; s≠ts \ne t) — a transition from state ss to state tt. The model also contains an implicit self-loop (s,s)(s, s) for every state ss (these are not listed in the input). No transition is listed twice.

The last line contains the property to verify, always of the form E(xU(AGy)), where x and y are atomic propositions.

Output

On the first line, print the number of states in which the verified property holds. On the following lines, print the numbers of those states in increasing order.

Examples2

  1. Example 1

    Input
    7 8 2
    1 a
    1 a
    2 a b
    1 b
    1 b
    1 a
    1 a
    1 2
    2 3
    3 4
    4 5
    5 3
    2 6
    6 7
    7 6
    E(aU(AGb))
    
    Expected output
    5
    1
    2
    3
    4
    5
    
  2. Example 2

    Input
    1 0 1
    1 a
    E(aU(AGa))
    
    Expected output
    1
    1