vector<int> TeamBuilder::specialLocations(vector<string> paths){
int N = paths.size();
vector<vector<int> > adj;
for(int i = 0; i < N; i ++){
string s = paths;
vector<int> row;
for(int j = 0; j < N; j++){
row.push_back(s[j] -'0');
}
adj.push_back(row);
}
for(int k = 0; k < N; k++){
for (int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
//i,j,k must be different
if(i==j || j == k || k==i)
continue;
//only update those no-paths
if(adj[j] == 0){
if(adj[k] !=0 && adj[k][j] != 0){
adj[j] = 1;
}
}
}
}
}
int firstNum = 0;
for(int i = 0 ; i < N; i++){
bool canReachAll = true;
for(int j = 0; j<N; j++){
if(j==i) continue;
if(adj[j] == 0){
canReachAll = false;
break;
}
}
if(canReachAll)
firstNum ++;
}
int secondNum = 0;
for(int j = 0 ; j < N; j++){
bool canBeReachedFromAll = true;
for(int i = 0; i<N; i++){
if(j!=i && adj[j] == 0){
canBeReachedFromAll = false;
break;
}
}
if(canBeReachedFromAll)
secondNum ++;
}
vector<int> res;
res.push_back(firstNum);
res.push_back(secondNum);
return res;
}
int N = paths.size();
vector<vector<int> > adj;
for(int i = 0; i < N; i ++){
string s = paths;
vector<int> row;
for(int j = 0; j < N; j++){
row.push_back(s[j] -'0');
}
adj.push_back(row);
}
for(int k = 0; k < N; k++){
for (int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
//i,j,k must be different
if(i==j || j == k || k==i)
continue;
//only update those no-paths
if(adj[j] == 0){
if(adj[k] !=0 && adj[k][j] != 0){
adj[j] = 1;
}
}
}
}
}
int firstNum = 0;
for(int i = 0 ; i < N; i++){
bool canReachAll = true;
for(int j = 0; j<N; j++){
if(j==i) continue;
if(adj[j] == 0){
canReachAll = false;
break;
}
}
if(canReachAll)
firstNum ++;
}
int secondNum = 0;
for(int j = 0 ; j < N; j++){
bool canBeReachedFromAll = true;
for(int i = 0; i<N; i++){
if(j!=i && adj[j] == 0){
canBeReachedFromAll = false;
break;
}
}
if(canBeReachedFromAll)
secondNum ++;
}
vector<int> res;
res.push_back(firstNum);
res.push_back(secondNum);
return res;
}