-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.cpp
More file actions
40 lines (34 loc) · 887 Bytes
/
Graph.cpp
File metadata and controls
40 lines (34 loc) · 887 Bytes
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
40
#include <bits/stdc++.h>
using namespace std;
int main()
{
// 頂点数
int cnt_vertex(0);
cin >> cnt_vertex;
vector<vector<int>> vecGraph(cnt_vertex,vector<int>(cnt_vertex,0));
int num_vertex(0), cnt_exit_vertex(0);
// 隣接行列を求める
for (int i = 0; i < cnt_vertex; i++)
{
cin >> num_vertex >> cnt_exit_vertex;
int num_next_vertex(0);
for (int j = 0; j < cnt_exit_vertex; j++)
{
cin >> num_next_vertex;
vecGraph[i][num_next_vertex-1] = 1;
}
}
// 結果の出力
for (int i = 0; i < cnt_vertex; i++)
{
for (int j = 0; j < cnt_vertex; j++)
{
if(j == cnt_vertex-1) {
cout << vecGraph[i][j] << "\n";
} else {
cout << vecGraph[i][j] << " ";
}
}
}
return 0;
}