-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTRR1014 1.14 DO THI.cpp
More file actions
93 lines (82 loc) · 1.99 KB
/
TRR1014 1.14 DO THI.cpp
File metadata and controls
93 lines (82 loc) · 1.99 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#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 im[101][10001]; // Increased size to handle more edges
void IncMat(){
int m = 0;
// Count total edges first
for (int u = 1; u <= n; u++){
for (int v = 1; v <= n; v++){
if (u != v) { // Typically don't count self-loops unless specified
m += a[u][v];
}
}
}
// Fill incidence matrix
int edge = 1;
for (int u = 1; u <= n; u++){
for (int v = 1; v <= n; v++){
for (int t = 1; t <= a[u][v]; t++){
if (u != v) { // Skip self-loops
// Initialize current edge column to 0
for (int k = 1; k <= n; k++) {
im[k][edge] = 0;
}
im[u][edge] = 1;
im[v][edge] = -1;
edge++;
}
}
}
}
cout << n << " " << m << "\n";
for(int u = 1; u <= n; u++){
for(int v = 1; v <= m; v++){
cout << im[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 {
IncMat();
}
return 0;
}