-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathf.cpp
63 lines (58 loc) · 1.02 KB
/
f.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
#define endl '\n'
#define eat cin
#define moo cout
#define int long long
using namespace std;
struct edge{
int u, v, w;
};
int N, F[2000][2000];
bool desc[2000][2000];
vector<edge> ans;
void dfs(int v){
while(true){
int mxv = -1, mxi = -1;
for(int i = 0; i < N; i++){
if(desc[v][i]){
if(F[v][i] > mxv){
mxv = F[v][i];
mxi = i;
}
}
}
if(!~mxi) break;
desc[v][mxi] = 0;
int vi = F[v][v] - F[v][mxi];
int vv = F[mxi][mxi] - F[v][mxi];
assert((vi + vv) % N == 0);
int x = (vi + vv) / N;
ans.push_back({v+1, mxi+1, x});
for(int i = 0; i < N; i++){
if(desc[v][i]){
if(F[v][i] < F[mxi][i]){
desc[mxi][i] = 1;
desc[v][i] = 0;
}
}
}
dfs(mxi);
}
}
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
eat >> N;
for(int i = 0; i < N; i++){
for(int j = 0; j <= i; j++){
eat >> F[i][j];
F[j][i] = F[i][j];
}
}
for(int i = 1; i < N; i++){
desc[0][i] = 1;
}
dfs(0);
for(edge e : ans){
moo << e.u << ' ' << e.v << ' ' << e.w << endl;
}
}