4fd800b3a8 2011-02-23 kinaba: #include <iostream> 4fd800b3a8 2011-02-23 kinaba: #include <sstream> 4fd800b3a8 2011-02-23 kinaba: #include <iomanip> 4fd800b3a8 2011-02-23 kinaba: #include <vector> 4fd800b3a8 2011-02-23 kinaba: #include <string> 4fd800b3a8 2011-02-23 kinaba: #include <map> 4fd800b3a8 2011-02-23 kinaba: #include <set> 4fd800b3a8 2011-02-23 kinaba: #include <algorithm> 4fd800b3a8 2011-02-23 kinaba: #include <numeric> 4fd800b3a8 2011-02-23 kinaba: #include <iterator> 4fd800b3a8 2011-02-23 kinaba: #include <functional> 4fd800b3a8 2011-02-23 kinaba: #include <complex> 4fd800b3a8 2011-02-23 kinaba: #include <queue> 4fd800b3a8 2011-02-23 kinaba: #include <stack> 4fd800b3a8 2011-02-23 kinaba: #include <cmath> 4fd800b3a8 2011-02-23 kinaba: #include <cassert> 4fd800b3a8 2011-02-23 kinaba: #include <cstring> 4fd800b3a8 2011-02-23 kinaba: using namespace std; 4fd800b3a8 2011-02-23 kinaba: typedef long long LL; 4fd800b3a8 2011-02-23 kinaba: typedef complex<double> CMP; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: class NetworkSecurity { public: 4fd800b3a8 2011-02-23 kinaba: int secureNetwork(vector <string> clientCable, vector <string> serverCable) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: int N = clientCable.size(); 4fd800b3a8 2011-02-23 kinaba: int M = serverCable[0].size(); 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: vector< vector<int> > cd(N, vector<int>(N)); 4fd800b3a8 2011-02-23 kinaba: for(int i=0; i<N; ++i) 4fd800b3a8 2011-02-23 kinaba: for(int j=0; j<N; ++j) 4fd800b3a8 2011-02-23 kinaba: if( clientCable[i][j]=='Y' ) 4fd800b3a8 2011-02-23 kinaba: cd[i][j] = 1; 4fd800b3a8 2011-02-23 kinaba: for(int k=0; k<N; ++k) 4fd800b3a8 2011-02-23 kinaba: for(int i=0; i<N; ++i) 4fd800b3a8 2011-02-23 kinaba: for(int j=0; j<N; ++j) 4fd800b3a8 2011-02-23 kinaba: cd[i][j] |= cd[i][k] & cd[k][j]; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: int cnt = 0; 4fd800b3a8 2011-02-23 kinaba: for(int i=0; i<N; ++i) 4fd800b3a8 2011-02-23 kinaba: for(int j=0; j<M; ++j) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: if( serverCable[i][j]=='Y' ) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: for(int k=0; k<N; ++k) 4fd800b3a8 2011-02-23 kinaba: if( cd[i][k]==1 && serverCable[k][j]=='Y' ) 4fd800b3a8 2011-02-23 kinaba: goto next; 4fd800b3a8 2011-02-23 kinaba: ++cnt; 4fd800b3a8 2011-02-23 kinaba: next:; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: return cnt; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: }; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // Powered by FileEdit 4fd800b3a8 2011-02-23 kinaba: // Powered by TZTester 1.01 [25-Feb-2003] : <cafelier&naoya_t>-custom 4fd800b3a8 2011-02-23 kinaba: // Powered by CodeProcessor