//\\__ hr1212 __//\\
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 800
#define MOD 1000000007
int k,n,m,b[30],mk[30];
char s[MAX];
vi v[MAX];
void dfs(int x){
mk[x]=1;
int i;
k++;
f(i,0,v[x].size()){
if(!mk[v[x][i]])
dfs(v[x][i]);
}
}
int main(){
int r,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;string p;
si(t);
while(t--){
clr(b,0);
clr(mk,0);
x1=y1=0;
while(1){
scanf("%s",s);
if(s[0]=='*')
break;
x=s[1]-'A';y=s[3]-'A';
v[x].pb(y);
v[y].pb(x);
}
gets(s);
gets(s);
f(i,0,strlen(s)){
if(s[i]>='A' && s[i]<='Z')
b[s[i]-'A']=1;
}
f(i,0,26){
if(b[i] && !mk[i]){
k=0;
dfs(i);
if(k==1)
x1++;
else
y1++;
}
}
f(i,0,26)
if(b[i])
v[i].clear();
printf("There are %d tree(s) and %d acorn(s).\n",y1,x1);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 800
#define MOD 1000000007
int k,n,m,b[30],mk[30];
char s[MAX];
vi v[MAX];
void dfs(int x){
mk[x]=1;
int i;
k++;
f(i,0,v[x].size()){
if(!mk[v[x][i]])
dfs(v[x][i]);
}
}
int main(){
int r,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;string p;
si(t);
while(t--){
clr(b,0);
clr(mk,0);
x1=y1=0;
while(1){
scanf("%s",s);
if(s[0]=='*')
break;
x=s[1]-'A';y=s[3]-'A';
v[x].pb(y);
v[y].pb(x);
}
gets(s);
gets(s);
f(i,0,strlen(s)){
if(s[i]>='A' && s[i]<='Z')
b[s[i]-'A']=1;
}
f(i,0,26){
if(b[i] && !mk[i]){
k=0;
dfs(i);
if(k==1)
x1++;
else
y1++;
}
}
f(i,0,26)
if(b[i])
v[i].clear();
printf("There are %d tree(s) and %d acorn(s).\n",y1,x1);
}
return 0;
}
No comments:
Post a Comment