#C10L06P04. C10.L06.图的表示与遍历.邻接矩阵.练习1.无向图的度
C10.L06.图的表示与遍历.邻接矩阵.练习1.无向图的度
题目描述
给出 个点, 条边的无向图,不存在重边,给一个节点 ,求出该节点的度。
输入格式
第 1 行,2 个整数 , ()。
接下来 行,每行 个整数,,表示边 ( ,)。
接下来一行一个整数 。
输出格式
一个整数。
样例
4 3
1 2
2 4
4 3
3
1
完成程序
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int a[N][N], n, m, x,res;
int main()
{
cin >> n >> m; //输入 n 个节点和 m 条边
for (int i = 1;i <= m; i++){ //建立图
int x, y;
cin >> x >> y;
__填空(1)__; // x 到 y 存在一条边
__填空(2)__; // y 到 x 存在一条边
}
cin >> x; //输入节点 x
for (int i = 1; i <= n; i++) {
if ( __填空(3)__ )
res++; //结果加 1
}
cout << res << endl;
return 0;
}
填空(1):{{ input(1) }}
填空(2):{{ input(2) }}
填空(3):{{ input(3) }}
相关
在以下作业中: