USACO chapter 2 section 2.3 Controlling Companies
USER: tian tianbing [tbbd4261] TASK: concom LANG: C++ Compiling... Compile: OK Executing... Test 1: TEST OK [0.011 secs, 3052 KB] Test 2: TEST OK [0.000 secs, 3052 KB] Test 3: TEST OK [0.000 secs, 3052 KB] Test 4: TEST OK [0.000 secs, 3052 KB] Test 5: TEST OK [0.000 secs, 3052 KB] Test 6: TEST OK [0.000 secs, 3052 KB] Test 7: TEST OK [0.000 secs, 3052 KB] Test 8: TEST OK [0.011 secs, 3052 KB] Test 9: TEST OK [0.324 secs, 3052 KB] All tests OK.Your program ('concom') produced all correct answers! This is your submission #2 for this problem. Congratulations!
/*
ID:tbbd4261
PROG:concom
LANG:C++
*/
#include<fstream>
#include<cstring>
using namespace std;
ifstream fin("concom.in");
ofstream fout("concom.out");
int d[101][101]={0};
bool f[101]={0};
bool own[101]={0};
int cnt[101]={0};
int n,i,j,p,m=0;
void dfs(int i)
{
if(f[i])return ;
f[i]=true;
for(int j=1;j<=m; j++ )
{
cnt[j]+=d[i][j];
if(cnt[j]>50)own[j]=true;
if(own[j])dfs(j);
}
}
int main()
{
fin>>n;
for(int k=1; k<=n; k++){
fin>>i>>j>>p; d[i][j]+=p;
if(i>m)m=i; if(j>m)m=j;
}
for(i=1; i<=m; i++)
{
memset(f,0,sizeof f);
memset(own,0,sizeof own);
memset(cnt,0,sizeof cnt);
dfs(i);
for(j=1; j<=m; j++)
if(own[j]&&j!=i)fout<<i<<' '<<j<<endl;
}
return 0;
}
posted on 2010-08-02 21:05 田兵 閱讀(205) 評論(0) 編輯 收藏 引用 所屬分類: USACO