//\\__ 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 1000100
#define MOD 1000000007
int n,m,graph[30][30],mk[30],con[30];
int main(){
int r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0,yr,prevc;
ll ans=0;string p;
while(si(n)!=EOF){
prevc=0;
yr=0;
clr(mk,0);
clr(graph,0);
clr(con,0);
si(m);
cin>>p;
f(i,0,3){
mk[p[i]-'A']=1;
con[p[i]-'A']=3;
}
f(i,0,m){
cin>>p;
graph[p[0]-'A'][p[1]-'A']=1;
graph[p[1]-'A'][p[0]-'A']=1;
}
while(1){
c=0;
f(i,0,26){
if(con[i]>=3)
c++;
}
if(prevc==c || c==n)
break;
prevc=c;
yr++;
vi v;
f(i,0,26){
f(j,0,26){
if(graph[i][j] && mk[i] && !mk[j]){
con[j]++;
if(con[j]==3)
v.pb(j);
}
}
}
f(i,0,v.size())
mk[v[i]]=1;
f(i,0,26){
if(!mk[i])
con[i]=0;
}
}
if(c!=n)
printf("THIS BRAIN NEVER WAKES UP\n");
else
printf("WAKE UP IN, %d, YEARS\n",yr);
}
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 1000100
#define MOD 1000000007
int n,m,graph[30][30],mk[30],con[30];
int main(){
int r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0,yr,prevc;
ll ans=0;string p;
while(si(n)!=EOF){
prevc=0;
yr=0;
clr(mk,0);
clr(graph,0);
clr(con,0);
si(m);
cin>>p;
f(i,0,3){
mk[p[i]-'A']=1;
con[p[i]-'A']=3;
}
f(i,0,m){
cin>>p;
graph[p[0]-'A'][p[1]-'A']=1;
graph[p[1]-'A'][p[0]-'A']=1;
}
while(1){
c=0;
f(i,0,26){
if(con[i]>=3)
c++;
}
if(prevc==c || c==n)
break;
prevc=c;
yr++;
vi v;
f(i,0,26){
f(j,0,26){
if(graph[i][j] && mk[i] && !mk[j]){
con[j]++;
if(con[j]==3)
v.pb(j);
}
}
}
f(i,0,v.size())
mk[v[i]]=1;
f(i,0,26){
if(!mk[i])
con[i]=0;
}
}
if(c!=n)
printf("THIS BRAIN NEVER WAKES UP\n");
else
printf("WAKE UP IN, %d, YEARS\n",yr);
}
return 0;
}
No comments:
Post a Comment