-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountThePaths.cpp
More file actions
57 lines (55 loc) · 1.1 KB
/
countThePaths.cpp
File metadata and controls
57 lines (55 loc) · 1.1 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
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int cnt = 0;
void dfs(int s, int d, vector<int> adj[], vector<bool> &vis)
{
if (s == d)
{
cnt++;
return;
}
vis[s] = 1;
for (int i : adj[s])
{
if (!vis[i])
{
dfs(i, d, adj, vis);
}
}
vis[s] = 0;
}
int main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tc;
cin >> tc;
while (tc--)
{
cnt = 0;
int n, e;
cin >> n >> e;
vector<int> adj[n];
for (int i = 0; i < e; i++)
{
int a, b;
cin >> a >> b;
adj[a].push_back(b);
}
int s, d;
cin >> s >> d;
vector<bool> vis(n, 0);
dfs(s, d, adj, vis);
cout << cnt << "\n";
}
// #ifndef ONLINE_JUDGE
// cout << "\nTime Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
// #endif
return 0;
}