Minimum Spanning Tree by 51b

n[],h['bc'],*p=n;i,a,b;main(c){for(;~scanf("%s%s%d",&a,&b,&c);n[h[b]=c-~c]=b)n[h[a]=2*c]=a;for(;p+=2,++i<130;)for(c=*p?a=h[*p],b=h[p[1]],!printf("%c %s %s %d\n",a-b?84:70,p,p+1,i):0;++c<'bc';)h[h[c]-b?0:c]=a;}

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

download

return to the top page