SWUST OJ 1062: 有向图的边存在判断 C++实现

题目描述

假设有向图G采用邻接矩阵存储,判断图G中是否存在边。

输入

第一行第一个整数n表示顶点的个数(顶点编号为0到n-1),第二行表示顶点i和j,接下来是为一个n*n大小的整数矩阵,表示图的邻接关系。数字为0表示不邻接,1表示不邻接。

输出

yes(存在),no(不存在)。
#include<bits/stdc++.h>
using namespace std;
int n, x, y, g = 0, m;
int main(){
	cin>>n;
	cin>>x>>y;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin>>m;
			if( i == x && j == y && m == 1) g = 1;
		}
	}
	cout<<((g==1)?"yes":"no");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/Ljy_Cxy/article/details/131465265