From 3590c0c4af96c347b6b32f5f281d193d331b1c8a Mon Sep 17 00:00:00 2001 From: shubhankk7 <56992145+shubhankk7@users.noreply.github.com> Date: Fri, 25 Oct 2019 11:46:49 +0530 Subject: [PATCH] Create PT07Y.cpp --- PT07Y.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 PT07Y.cpp diff --git a/PT07Y.cpp b/PT07Y.cpp new file mode 100644 index 0000000..461ddb5 --- /dev/null +++ b/PT07Y.cpp @@ -0,0 +1,54 @@ +#include +using namespace std; +vectorgraph[10000]; +long int n,m,i,j; +bool iscycle(long int s,bool visited[],long int parent) +{ + visited[s]=true; + vector::iterator it; + for(it=graph[s].begin();it!=graph[s].end();it++) + { + if(visited[*it]==false) + { + if(iscycle(*it,visited,s)) + return true; + } + else if(*it!=parent) + return true; + } + return false; +} +bool istree(long int s) +{ + bool visited[n]; + memset(visited,false,sizeof(visited)); + //cout<<"here"; + if(iscycle(i,visited,-1)) + return false; + for(long int i=0;i>n>>m; + //long int i,j; + while(m--) + { + cin>>i>>j; + i--,j--; + addedge(i,j); + } + //cout<