Minimum Spanning Tree by 51b

s[];t['bc'];n,*x=s,y;c(int*a){return a[2]-1[&a][2];}main(m){for(;~scanf(~n%3?"%s":"%d",s+n);n++)~n%3?t[m=s[n]]=m:0;for(qsort(s,n/3,12,c);x<s+n;x+=3)for(m=t[x[1]],y=printf("%c %s %s %d\n",t[*x]-m?84:70,x,x+1,x[2]);++y<'bc';)t[y]=t[m-t[y]?y:*x];}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page