Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <stdio.h>
- using namespace std;
- vector <vector <int > >adj;
- vector <pair <int, int > >archi;
- vector <int> attrazioni;
- vector <bool> visitato;
- void dfs ( int n)
- {
- visitato[n]= true;
- for(vector<int>::iterator it=adj[n].begin(); it!=adj[n].end(); it++)
- {
- if(!visitato[*it])
- {
- dfs(*it);
- }
- }
- }
- int main()
- {
- int N , A, Mg ,Mb ,Mt;
- freopen ("input.txt", "r", stdin);
- freopen ("output.txt", "w", stdout);
- cin>>N;
- cin>>A;
- cin>>Mg;
- cin>>Mb;
- cin>>Mt;
- for ( int i=0;i<A;i++)
- {
- int temp;
- cin>>temp;
- attrazioni.push_back(temp);
- }
- for(int i=0;i<(Mg+Mb+Mt);i++)
- {
- int temp;
- int temp1;
- cin>>temp;
- cin>>temp1;
- archi.push_back(make_pair(temp,temp1));
- }
- visitato.resize(N,false);
- adj.resize(N);
- for(int i=0;i<Mg;i++)
- {
- int temp;
- int temp1;
- temp=archi[i].first;
- temp1 = archi[i].second;
- adj[temp].push_back(temp1);
- adj[temp1].push_back(temp);
- }
- dfs(0);
- int conta=0;
- for(int i= 0;i<A;i++)
- {
- if(visitato[attrazioni[i]])
- {
- conta += 1;
- }
- }
- cout<<conta<<endl;
- visitato.clear();
- visitato.resize(N,false);
- for(int i=0;i<N;i++)
- {
- adj[i].clear();
- }
- adj.clear();
- adj.resize(N);
- for(int i=0;i<(Mg+Mb);i++)
- {
- int temp;
- int temp1;
- temp=archi[i].first;
- temp1 = archi[i].second;
- adj[temp].push_back(temp1);
- adj[temp1].push_back(temp);
- }
- dfs(0);
- conta =0;
- for(int i= 0;i<A;i++)
- {
- if(visitato[attrazioni[i]])
- {
- conta += 1;
- }
- }
- cout<<conta<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement