Untitled
unknown
c_cpp
4 years ago
917 B
10
Indexable
#include<bits/stdc++.h>
using namespace std;
int main(){
//matrix of size 8*8 is made
int**am=new int*[8];
//all cells are initialised to 0 as initially no edges are there
for(int i=0;i<8;i++){
am[i]=new int[8];
for(int j=0;j<8;j++){
am[i][j]=0;
}
}
//edges are added in the form am[from][to]=1
am[0][1]=1;am[0][5]=1;
am[1][2]=1;
am[2][3]=1;
am[4][2]=1;am[4][3]=1;am[4][5]=1;
am[5][1]=1;
am[6][0]=1;am[6][1]=1;am[6][5]=1;am[6][7]=1;
am[7][0]=1;
//check row wise for sink nodes
for(int i=0;i<8;i++){
bool temp=false;
//temp is false initially, inside inner loop, if 1 is encountered in a cell, temp changes to true.
for(int j=0;j<8;j++){
if(am[i][j]==1){
temp=true;
break;
}
}
//if temp is false after inner loop completes, all 0s were there in therow and hence it is a sink node.
if(temp==false)
cout<< i<<endl;
}
}Editor is loading...