-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
72 lines (64 loc) · 1.39 KB
/
Copy pathD.cpp
File metadata and controls
72 lines (64 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(),v.end()
#define X first
#define Y second
#define rep(x, y, z) for(ll (z) = (x); (z) < (y); (z)++)
int constexpr N = 2 * 1e5 + 10;
int constexpr MOD = 1e9 + 7;
ll constexpr INF = 1e13;
int n, m, k;
vector<int> g[N], pol;
set<int> p[N];
bool mk[N];
ll dist[N];
void bfs(int v) {
mk[v] = true;
queue<int> q;
q.push(v);
dist[v] = 0;
while (!q.empty()) {
v = q.front();
q.pop();
for (auto u : g[v]) {
if (!mk[u]) {
dist[u] = dist[v] + 1;
p[u].insert(v);
q.push(u);
mk[u] = true;
}
else if (dist[v] + 1 == dist[u]) {
p[u].insert(v);
}
}
}
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin >> n >> m;
fill(dist, dist + n, INF);
rep (0, m, i) {
int u, v;
cin >> v >> u;
g[--u].push_back(--v);
}
cin >> k;
rep (0, k, i) {
int v;
cin >> v;
pol.push_back(--v);
}
bfs(pol[k - 1]);
ll cntmn = 0, cntmx = 0;
rep (1, k, i) {
if (p[pol[i - 1]].count(pol[i])) {
if (p[pol[i - 1]].size() > 1) cntmx++;
} else {
cntmn++;
cntmx++;
}
}
cout << cntmn << ' ' << cntmx;
return 0;
}