int main() { //assert(freopen("input.txt", "r", stdin)); //assert(freopen("output.txt", "w", stdout)); //std::ios::sync_with_stdio(0); //std::cin.tie(0); int n; scanf("%d", &n); int src = 0; int dst = n + n + 1; for (int i = 1; i <= n; ++i) { add(src, i, 0, 1); add(i + n, dst, 0, 1); } for (int u, v, c; ~scanf("%d %d %d", &u, &v, &c); ) { add(u, v + n, c, 1); } int fcost = min_cost_max_flow(src, dst); printf("%d\n", fcost); for (int i = 1; i <= n; ++i) { int v = 0; for (int j = 0; j < int(ed[i].size()) && !v; ++j) { edge& e = ed[i][j]; if (n + 1 <= e.to && e.to <= n + n) { if (e.f) { v = e.to - n; } } } printf("%d %d\n", i, v); } }
int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif int t; scanf("%d",&t); while(t--) { scanf("%d %d %d\n",&n,&k,&m); memset(num,0,sizeof(num)); memset(mat,0,sizeof(mat)); for(int i=0;i<n;i++) { char c[3]; scanf("%s",c); ans[i]=c[0]-'A'; } for(int i=0;i<60;i++) for(int j=0;j<60;j++) cost[i][j]=inf; for(int i=0;i<m;i++) { memset(num,0,sizeof(num)); memset(mat,0,sizeof(mat)); for(int i=0;i<60;i++) for(int j=0;j<60;j++) cost[i][j]=inf; for(int j=0;j<n;j++) { char c[3]; scanf("%s",c); // puts(c); int x=c[0]-'A'; hash[ans[j]][num[ans[j]]++]=x; } for(int j=0;j<26;j++) //change j to k { for(int k=0;k<26;k++) { int tmp=0; for(int l=0;l<num[j];l++) { if(hash[j][l]!=k) tmp++; } if(num[j]) { mat[j][k+26]=1; cost[j][k+26]=tmp; } } } for(int j=0;j<26;j++) { mat[55][j]=1; cost[55][j]=0; mat[j+26][56]=1; cost[j+26][56]=0; } int t; min_cost_max_flow(60,mat,cost,55,56,flow,t); printf("%.4f\n",double(n-t)/double(n)); } } return 0; }