fork download
  1. #include<cstdio>
  2. #include<iostream>
  3. using namespace std;
  4. #define MAX 2001
  5. #define rl(x) scanf("%d",&x)
  6. int main()
  7. {
  8.  
  9. int c=0,n;
  10. rl(n);
  11. string s[n];
  12. for(int i=0;i<n;i++)
  13. cin>>s[i];
  14. for(int k=0;k<n;k++)
  15. for(int i=0;i<n;i++)
  16. for(int j=0;j<n;j++)
  17. {
  18. if(s[i][j]=='0' && i!=j)
  19. {
  20.  
  21. if(s[i][k]&&s[k][j])
  22. {
  23. c++;
  24. s[i][j]='1',s[j][i]='1';
  25. }
  26. }
  27. }
  28. printf("%d\n",2*c);
  29.  
  30. }
Success #stdin #stdout 0s 2820KB
stdin
4

0111
1000
1000
1000
stdout
6