fork download
  1. #include <queue>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. using namespace std;
  6. #define INF 100
  7. class Egalitarianism{
  8. public:
  9. int maxDifference(vector <string> isFriend, int d){
  10. int a[55];
  11. int ret = 0;
  12. int N = isFriend.size();
  13. for( int i=0; i<N; i++ ){
  14. for( int j=0; j<N; j++ ) a[j]=INF;
  15. a[i]=0;
  16. queue<int> q;
  17. q.push( i );
  18. while( !q.empty() ){
  19. int j = q.front(); q.pop();
  20. for( int k=0; k<N; k++ ){
  21. if( isFriend[j][k] == 'Y' && a[k] == INF ){
  22. a[k] = a[j]+1;
  23. q.push( k );
  24. }
  25. }
  26. }
  27. int b = *max_element( a, a+N );
  28. ret = max( ret, b );
  29. }
  30. if( ret == INF ) return -1;
  31. return ret * d;
  32. }
  33. };
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty