https://www.codechef.com/KM252020/problems/KM25P5B

In the above question what this line means ?

Print the lexicographical-ly(alphabetically) smallest string possible if the names of the array A are appended one after the other, without spaces, such that they follow any path in the graph.

```
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<string> v(n);
for(int i =0; i < n; i++){
cin >> v[i];
}
string answer = v[0];
int grid[n][n];
for(int i =0; i <n; i++){
for(int j = 0; j < n; j++){
cin >> grid[i][j];
}
}
int curr = 0;
while(true){
int curr_before = curr;
for(int i = 0; i < n; i++){
if(grid[curr][i] == 1){
answer += v[i];
curr = i;
break;
}
}
if(curr == curr_before){
break;
}
}
cout<<answer<<"\n";
}
```

for the input :

5

abcdd abcdd kooa olop bbba

0 1 0 0 0

0 0 1 1 0

0 0 0 1 1

0 0 0 0 0

0 0 0 0 0

the above solution give : â€śabcddabcddkooaolopâ€ť but why it is valid as it consider path(0->1->2->3) but if i consider path 0>1->2->4 then resultant string will be â€śabcddabcddkooabbbaâ€ť which is lexicographically smaller than other.

@chandubaba