USACO 2.3.5 Controlling Companies

USACO 2.3.5 Controlling Companies
唉..做得烂洗了..

/**/ /*
ID: lorelei3
TASK: concom
LANG: C++
*/


#include 
< fstream >
#include 
< memory.h >

using   namespace  std;

const   int  MAX  =   101 ;
const   int  NCON  =   100 ;
int  N,x;
int  a[MAX][MAX];
int  c[MAX];
bool  f[MAX];
ifstream fin;
ofstream fout;

void  dfs( int  k) {
    f[k]
=true;
    
for(int i=1; i<=NCON; ++i){
        c[i] 
+= a[k][i];
        
if(!f[i] && c[i]>50){
            dfs(i);
        }

    }

}


void  show() {
    
for(int i=1; i<=NCON; ++i)
            
if(i!=&& c[i]>50)
                fout
<<x<<" "<<i<<endl;
    
return;
}


int  main() {
    
int i,j,p,k;

    fin.open(
"concom.in");
    fout.open(
"concom.out");

    fin
>>N;

    
for(k=0; k<N; k++){
        fin
>>i>>j>>p;
        a[i][j]
=p;
    }


    
for(k=1; k<=NCON; ++k){
        memset(f, 
0sizeof(f));
        memset(c, 
0sizeof(c));
        x
=k;
        dfs(k);
        show();
    }

    
return 0;
}

你可能感兴趣的:(USACO 2.3.5 Controlling Companies)