import java.util.*;
import java.lang.*;
import java.io.*;

// The main method must be in a class named "Main".
class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int N, K, M;
        StringTokenizer st = new StringTokenizer(br.readLine());
        N = Integer.parseInt(st.nextToken());
        K = Integer.parseInt(st.nextToken());
        M = Integer.parseInt(st.nextToken());

        ArrayList<Integer>[] graph = new ArrayList[N];
        
        for (int i=0; i<N; i++) 
            graph[i] = new ArrayList<>();
        
        
        int[] connected = new int[N];
    
        for (int i=0; i<K; i++) {
            st = new StringTokenizer(br.readLine());
            int p = Integer.parseInt(st.nextToken())-1;
            int c = Integer.parseInt(st.nextToken())-1;
            graph[p].add(c);
            connected[c] ++;
           
        }

        Queue<Integer> q = new ArrayDeque<>();
        long[] execute_count = new long[N];

        for (int i=0; i<M; i++) {
            int n = Integer.parseInt(br.readLine())-1;
            execute_count[n]++;
        }
        
        for (int i=0; i<N; i++) {
            if (connected[i] == 0) {
                q.add(i);
            }
        }
        
        long count = 0;
        
        while (!q.isEmpty()) {
            int now = q.poll();
            count = (count + execute_count[now])%1000000007;
            
            for (int next : graph[now]) {
                execute_count[next] = (execute_count[now] + execute_count[next])%1000000007;
                connected[next]--;
                if (connected[next] == 0) {
                    q.add(next);
                    
                }
            }
        }

         
        System.out.println(count);
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: