Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- #define pb(x) push_back(x)
- using namespace std;
- const int N = 100005;
- typedef pair<int,int> ii;
- int n,m,par[N],cnt=0,num[N],low[N];
- vector<int> a[N],aa,bb;
- int ans=0;
- int k,l;
- int c[3][N];
- void dfs(int u)
- {
- num[u] = low[u] = ++cnt;
- for(int &v : a[u])
- {
- if (par[u] == v) continue;
- if (par[v]) low[u]=min(low[u],num[v]);
- else
- {
- par[v] = u;
- dfs(v);
- c[1][u] += c[1][v];
- c[2][u] += c[2][v];
- low[u]=min(low[u],low[v]);
- if (low[v] == num[v]) {
- if (c[1][v] == 0 || c[1][v] == k)
- {
- ans++;
- }
- else if (c[2][v] == 0 || c[2][v] == l)
- {
- ans++;
- }
- }
- }
- }
- }
- signed main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);cout.tie(0);
- freopen("net.inp","r",stdin);
- freopen("net.out","w",stdout);
- cin >> n >> m >> k >> l;
- for(int i=1; i<=k; ++i)
- {
- int x;
- cin >> x;
- c[1][x]=1;
- }
- for(int i=1; i<=l; ++i)
- {
- int x;
- cin >> x;
- c[2][x]=1;
- }
- for(int i=1; i<=m; ++i)
- {
- int u, v;
- cin >> u >> v;
- a[u].pb(v);
- a[v].pb(u);
- }
- for(int i=1; i<=n; ++i)
- {
- if (!par[i])
- {
- par[i] = -1;
- dfs(i);
- }
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment