UVa 11518 - Dominos 2
/*
Lionel Messi is such a player that you may catch him, you may touch him, you may feel him
and definitely you may Love him.
Lionel Messi is Messi. A little Magician in this World.
*/
// Accepted
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
#define mset(c,v) memset(c , v , sizeof c)
#define loop0(n) for(int i=0; i<n; i++)
#define loop1(n) for(int i=1; i<=n; i++)
#define mpair(x , y) make_pair(x , y)
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)
#define psb push_back
typedef unsigned long long ull;
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef vector<string>vs;
typedef map<int, int>mpii;
typedef map<string, int>mpsi;
typedef map<char, int>mpci;
typedef map<LL, LL>mpll;
const int mod = 1000007;
const int high = 20003;
struct printf
{
void ek(int n){cout << n << "\n";}
void dui(int x , int y) { cout << x << " " << y << "\n"; }
void tin(int x , int y , int z) { cout << x << " " << y << " " << z << "\n"; }
}tp;
struct sieve
{
int prm[high], plen=0;
bitset<high>bs;
void get_prime()
{
LL i , j;
bs.set();
bs[0]=bs[1]=0;
for(i=2; i<=high; i++)
{
if(bs[i])
{
prm[plen++] = i;
for(j=i*i; j<=high; j+=i) bs[j] = 0;
}
}
}
void pprm(){ for(int i=0; i<100; i++) cout << prm[i] << "; "; }
}prime;
vii adj[high];
bool visited[high];
void clear_adj()
{
for(int i=0; i<high; i++)
{
adj[i].clear();
}
}
void DFS(int s)
{
visited[s] = true;
int cnt = 0;
for(int i=0; i<adj[s].size(); i++)
{
int v = adj[s][i];
if(!visited[v])
{
visited[v] = true;
DFS(v);
}
}
}
int main()
{
fast;
int t, i , ans , u, v , x , n , m , l;
cin >> t;
while(t--)
{
clear_adj();
mset(visited , false);
cin >> n >> m >> l;
for(i=0; i<m; i++)
{
cin >> u >> v;
adj[u].psb(v);
//adj[v].psb(u);
}
for(i=0; i<l; i++)
{
cin >> x;
//mset(visited , false);
DFS(x);
}
ans=0;
for(i=1; i<=n; i++)
{
if(visited[i])
{
ans+=1;
//cout << i << "; ";
}
}
outn(ans);
}
return 0;
}
Lionel Messi is such a player that you may catch him, you may touch him, you may feel him
and definitely you may Love him.
Lionel Messi is Messi. A little Magician in this World.
*/
// Accepted
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
#define mset(c,v) memset(c , v , sizeof c)
#define loop0(n) for(int i=0; i<n; i++)
#define loop1(n) for(int i=1; i<=n; i++)
#define mpair(x , y) make_pair(x , y)
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)
#define psb push_back
typedef unsigned long long ull;
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef vector<string>vs;
typedef map<int, int>mpii;
typedef map<string, int>mpsi;
typedef map<char, int>mpci;
typedef map<LL, LL>mpll;
const int mod = 1000007;
const int high = 20003;
struct printf
{
void ek(int n){cout << n << "\n";}
void dui(int x , int y) { cout << x << " " << y << "\n"; }
void tin(int x , int y , int z) { cout << x << " " << y << " " << z << "\n"; }
}tp;
struct sieve
{
int prm[high], plen=0;
bitset<high>bs;
void get_prime()
{
LL i , j;
bs.set();
bs[0]=bs[1]=0;
for(i=2; i<=high; i++)
{
if(bs[i])
{
prm[plen++] = i;
for(j=i*i; j<=high; j+=i) bs[j] = 0;
}
}
}
void pprm(){ for(int i=0; i<100; i++) cout << prm[i] << "; "; }
}prime;
vii adj[high];
bool visited[high];
void clear_adj()
{
for(int i=0; i<high; i++)
{
adj[i].clear();
}
}
void DFS(int s)
{
visited[s] = true;
int cnt = 0;
for(int i=0; i<adj[s].size(); i++)
{
int v = adj[s][i];
if(!visited[v])
{
visited[v] = true;
DFS(v);
}
}
}
int main()
{
fast;
int t, i , ans , u, v , x , n , m , l;
cin >> t;
while(t--)
{
clear_adj();
mset(visited , false);
cin >> n >> m >> l;
for(i=0; i<m; i++)
{
cin >> u >> v;
adj[u].psb(v);
//adj[v].psb(u);
}
for(i=0; i<l; i++)
{
cin >> x;
//mset(visited , false);
DFS(x);
}
ans=0;
for(i=1; i<=n; i++)
{
if(visited[i])
{
ans+=1;
//cout << i << "; ";
}
}
outn(ans);
}
return 0;
}
Comments
Post a Comment