-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTRR1013 1.13 DO THI.cpp
More file actions
75 lines (67 loc) · 1.4 KB
/
TRR1013 1.13 DO THI.cpp
File metadata and controls
75 lines (67 loc) · 1.4 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int t, n, a[101][101];
void OpenFile() {
freopen("DT.INP", "r", stdin);
freopen("DT.OUT", "w", stdout);
}
void ReadData() {
cin >> t >> n;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cin >> a[i][j];
}
}
}
int degIn[101], degOut[101];
void CalcDegInOut(){
for (int u = 1; u <= n; u++){
degIn[u] = 0;
degOut[u] = 0;
}
for (int u = 1; u <= n; u++){
for (int v = 1; v <= n; v++) {
if (a[u][v]) {
degOut[u]++;
degIn[v]++;
}
}
}
for (int u = 1; u <= n; u++)
cout << degIn[u] << " " << degOut[u] << endl;
}
int adj[101][101];
void AdjList(){
cout << n << "\n";
int u, v, t;
for (u = 1; u<= n; u++){
t = 0;
for (v = 1; v <= n; v++){
if (a[u][v] > 0){
t++; adj[u][t] = v;
}
adj[u][0] = t;
}
}
for(u = 1; u <= n; u++){
cout << adj[u][0] << " ";
for(v = 1; v <= adj[u][0]; v++){
cout << adj[u][v] << " ";
}
cout << "\n";
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
OpenFile();
ReadData();
if (t == 1) {
CalcDegInOut();
} else {
AdjList();
}
return 0;
}