German Collegiate Programming Contest 2015

 1 // Legacy Code
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <string>
 6 #include <algorithm>
 7 #include <utility>
 8 #include <vector>
 9 #include <map>
10 #include <queue>
11 #include <stack>
12 #include <cstdlib>
13 #include <cmath>
14 typedef long long ll;
15 #define lowbit(x) (x&(-x))
16 #define ls l,m,rt<<1
17 #define rs m+1,r,rt<<1|1
18 using namespace std;
19 const int N=550;
20 string s;
21 vector<int>v[N];
22 vector<string>vs[N];
23 map<int,string>mp;
24 map<string,int>mp1;
25 int n,k;
26 bool vis[N];
27 void dfs(int x)
28 {
29     vis[x]=1;
30     for(int j=0;j<v[x].size();j++){
31         if(!vis[v[x][j]])  dfs(v[x][j]);
32     }
33     return ;
34 }
35 int  main()
36 {
37     scanf("%d",&n);
38     for(int i=1;i<=n;i++)
39     {
40         cin>>s;
41         mp[i]=s;
42         mp1[s]=i;
43         //两个map来进行整形和字符串的转换
44         scanf("%d",&k);
45         for(int   j=0;j<k;j++)
46         {
47             cin>>s;
48             vs[i].push_back(s);
49         }
50     }
51     for(int  i=1;i<=n;i++)
52     {
53         for(int  j=0;j<vs[i].size();j++){
54             v[mp1[vs[i][j]]].push_back(i);//vs[i][j]可以调用i
55             }
56     }
57     memset(vis,0,sizeof(vis));
58     for(int i=1;i<=n;i++)
59     {
60         if(mp[i].find("PROGRAM")==mp[i].size()-7&&mp[i].size()!=6&&!vis[i]){
61             dfs(i);
62         }
63     }
64     int  ans=0;
65     for(int i=1;i<=n;i++)
66     {
67         if(!vis[i]) ans++;
68     }
69     printf("%d\n",ans);
70     return  0;
71 }

 

posted on 2018-07-14 16:06  cltt  阅读(140)  评论(0编辑  收藏  举报

导航