- #include <bits/stdc++.h>
- using namespace std;
- #define N 1005
- vector<int> adj[N];
- vector<int>people;
- int k, n, m;
- bool visited[N];
- int ct[N];
- void clear(){
- people.clear();
- memset(ct, 0, sizeof(ct));
- memset(visited,false, sizeof(visited));
- for(int i = 0; i <=n; i++){
- adj[i].clear();
- }
- }
- void dfs(int source){
- if(visited[source]) return;
- visited[source] = true;
- ct[source]++;
- //cout<<source<<" ";
- for(int i = 0; i < adj[source].size(); i++){
- dfs(adj[source][i]);
- }
- }
- int main(){
- int ts;
- scanf("%d", &ts);
- for(int c = 1; c <= ts; c++){
- clear();
- scanf("%d%d%d",&k, &n, &m);
- for(int i = 0; i <k; i++){
- int p;
- cin>>p;
- people.push_back(p);
- }
- for(int i = 0; i <m; i++){
- int a, b;
- scanf("%d%d", &a, &b);
- adj[a].push_back(b);
- }
- for(int i = 0; i <people.size(); i++) {dfs(people[i]); memset(visited, false, sizeof(visited));}
- int ans = 0;
- for(int i = 1; i <=n; i++) ans+= (ct[i]==people.size());
- //for(int i = 1; i <=n; i++) cout<<ct[i]<<" ";
- printf("Case %d: %d\n", c, ans);
- }
- return 0;
- }
Friday, 28 July 2017
Lightoj 1111 - Best Picnic Ever
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
-
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
No comments:
Post a Comment