-
Notifications
You must be signed in to change notification settings - Fork 1
/
lab1.cpp
39 lines (29 loc) 路 745 Bytes
/
lab1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Program to Find the Number of Vertices, Even Vertices, Odd Vertices and
// Number of Edges in a Graph
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
int degree[n] = {};
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
degree[i] += a[i][j];
}
}
int even = 0, odd = 0, edges = 0;
for (int i = 0; i < n; i++) {
even += (degree[i] % 2 == 0);
odd += (degree[i] % 2 != 0);
edges += degree[i];
}
cout << "number of even vertices" << " = " << even << '\n';
cout << "number of odd vertices" << " = " << odd << '\n';
cout << "number of edges" << " = " << edges / 2 << '\n';
}