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;
}