2
1
Fork 0
aoc2021/12/solution.c
2021-12-13 06:13:57 +01:00

40 lines
1.9 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct{
#define K(a\
,b) ((a&0x3f)\
<<6|(b&0x3f))
int n,e[8];}
G [K('z',
'z' )]={
0} ; int p[
64]={ 0},l=
0;int R(int l,int
D){ int C=0, c=p[l
-1],N ,d, i=0,j
;if(c ==1) return
1; for( ;i
<G[c].n; i++){N= G[c].e[i
];d=0;if(N){ if((N&0x800)){for (j=0;j<l;j++
)if(p[j]==N){d =1;break;}}if(!d||D){p [l]=N;C+=R(l+1
,d ? 0:D);}}} return C;} int k( char*s){return
(!strcmp(s,"" "star" "t" ))?0:( !strcmp(s,"e"
"nd"))?1 :K(s[0]/* I HATE */,s[1]) ;}int
main ()/* GRAPH THEORY */{ char
a[8] ,b[8];while(scanf ("%7"
"[^-]" "-%7"
"s\n" ,a,b)
==2){ int A
=k(a) ,B=k
(b);G [A].
e[G[A ].n++
]=B; G[
B].e[G[B
]. n++]=A;}
printf("Silver"
": %d Gold: %d"
"\n",R(1,0),
R(1,1));}