fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include<vector>
  4. using namespace std;
  5. char arr[2001][2001];
  6.  
  7. int main(void) {
  8. unsigned long int n;
  9. unsigned long int i,j,k;
  10. scanf("%lu",&n);
  11. vector<int>adj[n];
  12.  
  13. for(i=0;i<n;i++)
  14. {
  15. scanf("%s",arr[i]);
  16. for(j=0;j<n;j++)
  17. {
  18. if(arr[i][j]=='1')
  19. {
  20. adj[i].push_back(j);
  21.  
  22. }
  23. }
  24. }
  25.  
  26.  
  27. long int count=0;
  28. unsigned int p,q;
  29. for(i=0;i<n;i++)
  30. {
  31. for(j=0;j<adj[i].size();j++)
  32. {
  33. {
  34. for(k=j+1;k<adj[i].size();k++)
  35. {
  36. {
  37. p=adj[i][j];
  38. q=adj[i][k];
  39. if(arr[p][q]=='0')
  40. {
  41. arr[p][q]=arr[q][p]='2';
  42. count++;
  43.  
  44. }
  45. }
  46. }
  47. }
  48. }
  49. }
  50. printf("%ld\n",2*count);
  51. return 0;
  52. }
Success #stdin #stdout 0s 7340KB
stdin
5
01100
10010
10001
01000
00100
stdout
6