structVertex { int sum = 0; int degree = 0; vector<int> neighbors; };
intcalSum(vector<Vertex> A){ queue<int> queue;
for (int i = 0; i < A.size(); i++) if (A[i].degree == 0) queue.push(i);
int sum = 0; do { int root = queue.front(); queue.pop(); int curSum = A[root].sum; sum += curSum % 142857; sum %= 142857; vector<int> &neighbors = A[root].neighbors; for (int i = 0; i < neighbors.size(); i++) { A[neighbors[i]].sum += curSum; A[neighbors[i]].sum %= 142857; A[neighbors[i]].degree--; if (A[neighbors[i]].degree == 0) queue.push(neighbors[i]); } } while (!queue.empty());
return sum; }
intmain(){ int N = 0, M = 0, K = 0; cin >> N >> M >> K; vector<Vertex> A = vector<Vertex>(N); for (int i = 0; i < K; i++) { int a = 0; cin >> a; A[a - 1].sum++; } for (int i = 0; i < M; i++) { int a = 0, b = 0; cin >> a >> b; A[a - 1].neighbors.push_back(b - 1); A[b - 1].degree++; }