Test instructions: A company's control of Company B is conditional upon satisfying one of the following conditions: A=b,a's share of B is more than 50% per cent of the shares of company B, which exceeds 50%,a control.
Analysis: I divide the control relationship level: The first level is the direct shares more than 50%, the second level is at least need to be separated by the first level of control of the company to control the company, ...
From the first level to the second level, the second level to the third level ... The end condition is that this time there is no increase in any control relationship.
Http://train.usaco.org/usacoprob2?a=O1HFwuT0pRX&S=concom
/*task:concomlang:c++*/#include <cstdio> #include <cstring> #include <algorithm> #define LL Long Long #define file (s) freopen (#s ". In", "R", stdin), Freopen (#s ". Out", "w", stdout) using namespace std; #define N 105int M;int C[n] [N],g[n][n];int Main () {file (concom); scanf ("%d", &m); for (int i=1;i<=m;i++) {int u,v,w; scanf ("%d%d%d", &u,&v,&w); G[u][v]=w; if (w>50) {c[u][v]=1; } c[u][u]= c[v][v]=1; } for (int k=0;k==0;) {k=1; for (int i=1;i<=100;i++) {int ct=0,ut=0,con[n],ucn[n]; for (int j=1;j<=100;j++) if (C[i][j]) {con[++ct]=j;} else{Ucn[++ut]=j;} for (int j=1;j<=ut;j++) {int sum=0; for (int l=1;l<=ct;l++) {sum+=g[con[l]][ucn[j]]; if (sum>50) {k=0; C[i][ucn[j]]=1; BreaK }}}}} for (int i=1;i<=100;i++) for (int j=1;j<=100;j++) if (i! =J&&C[I][J]) printf ("%d%d\n", i,j); return 0;}
"Usaco 2.3" controlling Companies (Recursive)