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 田兵 阅读(170) 评论(0)  编辑 收藏 引用 所属分类: USACO


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2010年8月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
2930311234

导航

统计

常用链接

留言簿(2)

随笔分类(65)

随笔档案(65)

文章档案(2)

ACM

搜索

积分与排名

最新随笔

最新评论

阅读排行榜