Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- int c[5000], pi[5000], a[3], n;
- string graph[5000];
- vector<int> res;
- bool DFS(int v){
- c[v]=1;
- bool flag=false;
- for(int i=0;i<n;i++)
- if(graph[v][i]=='1' && c[i]==0){
- pi[i]=v;
- flag=flag || DFS(i);
- } else if(graph[v][i]=='1' && c[i]==1){
- if(pi[v]!=-1 && pi[pi[v]]!=-1 && pi[pi[v]]==i){
- res.push_back(i);
- res.push_back(pi[v]);
- res.push_back(v);
- return true;
- }
- }
- return flag;
- }
- int main()
- {
- cin>>n;
- for(int i=0;i<n;i++){
- cin>>graph[i];
- c[i]=0;
- pi[i]=0;
- }
- if(DFS(0))
- cout<<res[0]+1<<' '<<res[1]+1<<' '<<res[2]+1;
- else
- cout<<-1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement