Untitled
unknown
c_cpp
3 years ago
962 B
3
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; //this array will hold outdegree of each vertex. int outdegree[8]={0}; //calculate outdegree of each row and store in array outdegree for(int i=0;i<8;i++){ int count=0; for(int j=0;j<8;j++){ if(am[i][j]==1){ count++; } } outdegree[i]=count; } //maxi stores index with maximum value. int max=0,maxi=0; for(int i=0;i<8;i++){ if(max<outdegree[i]){ max=outdegree[i]; maxi=i; } } cout<<maxi<<endl; }
Editor is loading...