Created
April 6, 2016 02:41
-
-
Save nomarlo/d7e34aa3c05807817d8bb4c2be4ee6ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
La de idea de solución es considerar que el número de vertices (v) menos aruistas (e) nos da el númeo de árboles (incluyendo los "acorns") | |
Y además los vertices que no tengan ninguna arista son considerados como "acorns" | |
**/ | |
#include <iostream> | |
#include <cstdio> | |
#include <map> | |
#include <bitset> | |
using namespace std; | |
int t, n; | |
int v, a,e; | |
bitset <32> G; | |
int main(){ | |
scanf("%d\n",&t); | |
while(t--){ | |
string s; | |
v=a=e=0; | |
cin>>s; | |
G.reset(); | |
while(s[0]!='*'){ | |
G[s[1]-65]=1; | |
G[s[3]-65]=1; | |
cin>>s; | |
e++; | |
} | |
cin>>s; | |
int i=0; | |
//cout<<s<<endl; | |
if(!G[s[i]-65]) | |
a++; | |
v++; | |
i++; | |
while(s[i]==','){ | |
//cout<<s[i+1]; | |
if(!G[s[i+1]-65]) | |
a++; | |
v++; | |
i+=2; | |
//cout<<s[i]; | |
} | |
// cout<<e<<":"<<v; | |
printf("There are %d tree(s) and %d acorn(s).\n",(v-e)-a,a); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment