# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
722740 |
2023-04-12T18:47:42 Z |
gagik_2007 |
Graph (BOI20_graph) |
C++17 |
|
396 ms |
28388 KB |
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <chrono>
#include <ctime>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <limits>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <functional>
#include <random>
#include <cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
#define ff first
#define ss second
ll ttt;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll N = 200007;
const ll M = 307;
const ll LG = 31;
ll n, m, k;
vector<pair<int, int>>g[N];
bool used[N];
bool neg[N]; // if the x in the value formula has the negative sign
ll val[N]; // if neg[v]: value = val[v] - x, else: value = x + val[v]
bool defined_value[N];
ll vlx2[N];
bool is_root[N];
vector<int>cmp[N];
void dfs(int v, int par, int root) {
//cout << v << endl;
cmp[root].push_back(v);
for (auto e : g[v]) {
int to = e.ff;
int c = e.ss;
if (to != par) {
if (!used[to]) {
if (neg[v]) {
val[to] = c - val[v];
}
else {
neg[to] = true;
val[to] = c - val[v];
}
used[to] = true;
dfs(to, v, root);
}
else {
if (neg[v] == neg[to]) {
if (neg[v]) {
if (!defined_value[root]) {
vlx2[root] = val[v] + val[to] - c;
defined_value[root] = true;
//cout << "Defined: " << vlx2[root] << endl;
}
else if (vlx2[root] != val[v] + val[to] - c) {
cout << "NO\n";
exit(0);
}
}
else {
if (!defined_value[root]) {
vlx2[root] = c - val[v] - val[to];
defined_value[root] = true;
//cout << "Defined: " << vlx2[root] << endl;
}
else if (vlx2[root] != c - val[v] - val[to]) {
cout << "NO\n";
exit(0);
}
}
}
else {
if (val[v] + val[to] != c) {
cout << "NO\n";
exit(0);
}
}
}
}
}
}
ll get_sum(ll curvlx2, int root) {
//cout << "PROCESSING: " << curvlx2 << endl;
ll sum = 0;
for (int v : cmp[root]) {
ll vl = 0;
if (neg[v]) {
vl = val[v] * 2 - curvlx2;
}
else {
vl = val[v] * 2 + curvlx2;
}
//cout << vl << " ";
sum += abs(vl);
}
//cout << endl;
return sum;
}
int main() {
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
int tp;
cin >> x >> y >> tp;
g[x].push_back({ y,tp });
g[y].push_back({ x,tp });
}
for (int v = 1; v <= n; v++) {
if (!used[v]) {
used[v] = true;
is_root[v] = true;
dfs(v, -1, v);
}
}
cout << setprecision(12) << fixed;
cout << "YES\n";
vector<ld>ans(n + 1, 0);
for (int u = 1; u <= n; u++) {
if (is_root[u]) {
if (defined_value[u]) {
for (int v : cmp[u]) {
ld vl = 0;
if (neg[v]) {
vl = val[v] - ld(vlx2[u]) / 2.0;
}
else {
vl = val[v] + ld(vlx2[u]) / 2.0;
}
ans[v] = vl;
}
}
else {
pair<ll, ll>mn = { INF,INF };
for (ll cur = -M; cur <= M; cur++) {
mn = min(mn, { get_sum(cur,u),cur });
}
vlx2[u] = mn.ss;
for (int v : cmp[u]) {
ld vl = 0;
if (neg[v]) {
vl = val[v] - ld(vlx2[u]) / 2.0;
}
else {
vl = val[v] + ld(vlx2[u]) / 2.0;
}
ans[v] = vl;
}
}
}
}
for (int v = 1; v <= n; v++) {
cout << ans[v] << " ";
}
cout << endl;
}
/// ---- - -------- ------ -------- -- - - -
/// Just a reminder. Ubuntu password is I O I
/// ---- - -------- ------ -------- -- - - -
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
answer = YES |
2 |
Correct |
6 ms |
9684 KB |
answer = YES |
3 |
Correct |
6 ms |
9684 KB |
answer = YES |
4 |
Correct |
5 ms |
9684 KB |
answer = NO |
5 |
Correct |
5 ms |
9684 KB |
answer = YES |
6 |
Correct |
5 ms |
9684 KB |
answer = YES |
7 |
Correct |
6 ms |
9684 KB |
answer = YES |
8 |
Correct |
5 ms |
9684 KB |
answer = YES |
9 |
Correct |
5 ms |
9684 KB |
answer = NO |
10 |
Correct |
4 ms |
9684 KB |
answer = YES |
11 |
Correct |
5 ms |
9692 KB |
answer = YES |
12 |
Correct |
7 ms |
9684 KB |
answer = NO |
13 |
Correct |
7 ms |
9720 KB |
answer = YES |
14 |
Correct |
5 ms |
9700 KB |
answer = YES |
15 |
Correct |
5 ms |
9684 KB |
answer = YES |
16 |
Correct |
5 ms |
9684 KB |
answer = YES |
17 |
Correct |
6 ms |
9684 KB |
answer = YES |
18 |
Correct |
5 ms |
9684 KB |
answer = YES |
19 |
Correct |
5 ms |
9684 KB |
answer = YES |
20 |
Correct |
5 ms |
9684 KB |
answer = YES |
21 |
Correct |
5 ms |
9720 KB |
answer = YES |
22 |
Correct |
6 ms |
9684 KB |
answer = NO |
23 |
Correct |
6 ms |
9684 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
answer = YES |
2 |
Correct |
6 ms |
9684 KB |
answer = YES |
3 |
Correct |
6 ms |
9684 KB |
answer = YES |
4 |
Correct |
5 ms |
9684 KB |
answer = NO |
5 |
Correct |
5 ms |
9684 KB |
answer = YES |
6 |
Correct |
5 ms |
9684 KB |
answer = YES |
7 |
Correct |
6 ms |
9684 KB |
answer = YES |
8 |
Correct |
5 ms |
9684 KB |
answer = YES |
9 |
Correct |
5 ms |
9684 KB |
answer = NO |
10 |
Correct |
4 ms |
9684 KB |
answer = YES |
11 |
Correct |
5 ms |
9692 KB |
answer = YES |
12 |
Correct |
7 ms |
9684 KB |
answer = NO |
13 |
Correct |
7 ms |
9720 KB |
answer = YES |
14 |
Correct |
5 ms |
9700 KB |
answer = YES |
15 |
Correct |
5 ms |
9684 KB |
answer = YES |
16 |
Correct |
5 ms |
9684 KB |
answer = YES |
17 |
Correct |
6 ms |
9684 KB |
answer = YES |
18 |
Correct |
5 ms |
9684 KB |
answer = YES |
19 |
Correct |
5 ms |
9684 KB |
answer = YES |
20 |
Correct |
5 ms |
9684 KB |
answer = YES |
21 |
Correct |
5 ms |
9720 KB |
answer = YES |
22 |
Correct |
6 ms |
9684 KB |
answer = NO |
23 |
Correct |
6 ms |
9684 KB |
answer = NO |
24 |
Correct |
6 ms |
9684 KB |
answer = YES |
25 |
Correct |
6 ms |
9684 KB |
answer = YES |
26 |
Correct |
5 ms |
9684 KB |
answer = YES |
27 |
Correct |
6 ms |
9676 KB |
answer = YES |
28 |
Correct |
5 ms |
9684 KB |
answer = YES |
29 |
Correct |
5 ms |
9684 KB |
answer = YES |
30 |
Correct |
5 ms |
9684 KB |
answer = NO |
31 |
Correct |
5 ms |
9696 KB |
answer = YES |
32 |
Correct |
5 ms |
9684 KB |
answer = YES |
33 |
Correct |
5 ms |
9684 KB |
answer = YES |
34 |
Correct |
6 ms |
9684 KB |
answer = YES |
35 |
Correct |
5 ms |
9684 KB |
answer = YES |
36 |
Correct |
6 ms |
9684 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
answer = YES |
2 |
Correct |
6 ms |
9684 KB |
answer = YES |
3 |
Correct |
6 ms |
9684 KB |
answer = YES |
4 |
Correct |
5 ms |
9684 KB |
answer = NO |
5 |
Correct |
5 ms |
9684 KB |
answer = YES |
6 |
Correct |
5 ms |
9684 KB |
answer = YES |
7 |
Correct |
6 ms |
9684 KB |
answer = YES |
8 |
Correct |
5 ms |
9684 KB |
answer = YES |
9 |
Correct |
5 ms |
9684 KB |
answer = NO |
10 |
Correct |
4 ms |
9684 KB |
answer = YES |
11 |
Correct |
5 ms |
9692 KB |
answer = YES |
12 |
Correct |
7 ms |
9684 KB |
answer = NO |
13 |
Correct |
7 ms |
9720 KB |
answer = YES |
14 |
Correct |
5 ms |
9700 KB |
answer = YES |
15 |
Correct |
5 ms |
9684 KB |
answer = YES |
16 |
Correct |
5 ms |
9684 KB |
answer = YES |
17 |
Correct |
6 ms |
9684 KB |
answer = YES |
18 |
Correct |
5 ms |
9684 KB |
answer = YES |
19 |
Correct |
5 ms |
9684 KB |
answer = YES |
20 |
Correct |
5 ms |
9684 KB |
answer = YES |
21 |
Correct |
5 ms |
9720 KB |
answer = YES |
22 |
Correct |
6 ms |
9684 KB |
answer = NO |
23 |
Correct |
6 ms |
9684 KB |
answer = NO |
24 |
Correct |
6 ms |
9684 KB |
answer = YES |
25 |
Correct |
6 ms |
9684 KB |
answer = YES |
26 |
Correct |
5 ms |
9684 KB |
answer = YES |
27 |
Correct |
6 ms |
9676 KB |
answer = YES |
28 |
Correct |
5 ms |
9684 KB |
answer = YES |
29 |
Correct |
5 ms |
9684 KB |
answer = YES |
30 |
Correct |
5 ms |
9684 KB |
answer = NO |
31 |
Correct |
5 ms |
9696 KB |
answer = YES |
32 |
Correct |
5 ms |
9684 KB |
answer = YES |
33 |
Correct |
5 ms |
9684 KB |
answer = YES |
34 |
Correct |
6 ms |
9684 KB |
answer = YES |
35 |
Correct |
5 ms |
9684 KB |
answer = YES |
36 |
Correct |
6 ms |
9684 KB |
answer = YES |
37 |
Correct |
5 ms |
9684 KB |
answer = YES |
38 |
Correct |
5 ms |
9684 KB |
answer = YES |
39 |
Correct |
6 ms |
9756 KB |
answer = YES |
40 |
Correct |
6 ms |
9812 KB |
answer = YES |
41 |
Correct |
6 ms |
9684 KB |
answer = NO |
42 |
Correct |
7 ms |
9812 KB |
answer = YES |
43 |
Correct |
7 ms |
9812 KB |
answer = YES |
44 |
Correct |
8 ms |
9812 KB |
answer = YES |
45 |
Correct |
6 ms |
9812 KB |
answer = YES |
46 |
Correct |
6 ms |
9684 KB |
answer = YES |
47 |
Correct |
5 ms |
9812 KB |
answer = YES |
48 |
Correct |
6 ms |
9940 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
answer = YES |
2 |
Correct |
6 ms |
9684 KB |
answer = YES |
3 |
Correct |
6 ms |
9684 KB |
answer = YES |
4 |
Correct |
5 ms |
9684 KB |
answer = NO |
5 |
Correct |
5 ms |
9684 KB |
answer = YES |
6 |
Correct |
5 ms |
9684 KB |
answer = YES |
7 |
Correct |
6 ms |
9684 KB |
answer = YES |
8 |
Correct |
5 ms |
9684 KB |
answer = YES |
9 |
Correct |
5 ms |
9684 KB |
answer = NO |
10 |
Correct |
4 ms |
9684 KB |
answer = YES |
11 |
Correct |
5 ms |
9692 KB |
answer = YES |
12 |
Correct |
7 ms |
9684 KB |
answer = NO |
13 |
Correct |
7 ms |
9720 KB |
answer = YES |
14 |
Correct |
5 ms |
9700 KB |
answer = YES |
15 |
Correct |
5 ms |
9684 KB |
answer = YES |
16 |
Correct |
5 ms |
9684 KB |
answer = YES |
17 |
Correct |
6 ms |
9684 KB |
answer = YES |
18 |
Correct |
5 ms |
9684 KB |
answer = YES |
19 |
Correct |
5 ms |
9684 KB |
answer = YES |
20 |
Correct |
5 ms |
9684 KB |
answer = YES |
21 |
Correct |
5 ms |
9720 KB |
answer = YES |
22 |
Correct |
6 ms |
9684 KB |
answer = NO |
23 |
Correct |
6 ms |
9684 KB |
answer = NO |
24 |
Correct |
6 ms |
9684 KB |
answer = YES |
25 |
Correct |
6 ms |
9684 KB |
answer = YES |
26 |
Correct |
5 ms |
9684 KB |
answer = YES |
27 |
Correct |
6 ms |
9676 KB |
answer = YES |
28 |
Correct |
5 ms |
9684 KB |
answer = YES |
29 |
Correct |
5 ms |
9684 KB |
answer = YES |
30 |
Correct |
5 ms |
9684 KB |
answer = NO |
31 |
Correct |
5 ms |
9696 KB |
answer = YES |
32 |
Correct |
5 ms |
9684 KB |
answer = YES |
33 |
Correct |
5 ms |
9684 KB |
answer = YES |
34 |
Correct |
6 ms |
9684 KB |
answer = YES |
35 |
Correct |
5 ms |
9684 KB |
answer = YES |
36 |
Correct |
6 ms |
9684 KB |
answer = YES |
37 |
Correct |
5 ms |
9684 KB |
answer = YES |
38 |
Correct |
5 ms |
9684 KB |
answer = YES |
39 |
Correct |
6 ms |
9756 KB |
answer = YES |
40 |
Correct |
6 ms |
9812 KB |
answer = YES |
41 |
Correct |
6 ms |
9684 KB |
answer = NO |
42 |
Correct |
7 ms |
9812 KB |
answer = YES |
43 |
Correct |
7 ms |
9812 KB |
answer = YES |
44 |
Correct |
8 ms |
9812 KB |
answer = YES |
45 |
Correct |
6 ms |
9812 KB |
answer = YES |
46 |
Correct |
6 ms |
9684 KB |
answer = YES |
47 |
Correct |
5 ms |
9812 KB |
answer = YES |
48 |
Correct |
6 ms |
9940 KB |
answer = YES |
49 |
Correct |
34 ms |
10612 KB |
answer = YES |
50 |
Correct |
15 ms |
10964 KB |
answer = YES |
51 |
Correct |
24 ms |
10964 KB |
answer = YES |
52 |
Correct |
9 ms |
10228 KB |
answer = NO |
53 |
Correct |
8 ms |
9812 KB |
answer = YES |
54 |
Correct |
10 ms |
9940 KB |
answer = YES |
55 |
Correct |
18 ms |
10196 KB |
answer = YES |
56 |
Correct |
36 ms |
10596 KB |
answer = YES |
57 |
Correct |
27 ms |
10580 KB |
answer = YES |
58 |
Correct |
33 ms |
10448 KB |
answer = YES |
59 |
Correct |
14 ms |
10452 KB |
answer = YES |
60 |
Correct |
37 ms |
10500 KB |
answer = YES |
61 |
Correct |
9 ms |
10196 KB |
answer = YES |
62 |
Correct |
53 ms |
14400 KB |
answer = NO |
63 |
Correct |
60 ms |
15340 KB |
answer = YES |
64 |
Correct |
60 ms |
15052 KB |
answer = NO |
65 |
Correct |
60 ms |
15328 KB |
answer = YES |
66 |
Correct |
9 ms |
9876 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
answer = YES |
2 |
Correct |
6 ms |
9684 KB |
answer = YES |
3 |
Correct |
6 ms |
9684 KB |
answer = YES |
4 |
Correct |
5 ms |
9684 KB |
answer = NO |
5 |
Correct |
5 ms |
9684 KB |
answer = YES |
6 |
Correct |
5 ms |
9684 KB |
answer = YES |
7 |
Correct |
6 ms |
9684 KB |
answer = YES |
8 |
Correct |
5 ms |
9684 KB |
answer = YES |
9 |
Correct |
5 ms |
9684 KB |
answer = NO |
10 |
Correct |
4 ms |
9684 KB |
answer = YES |
11 |
Correct |
5 ms |
9692 KB |
answer = YES |
12 |
Correct |
7 ms |
9684 KB |
answer = NO |
13 |
Correct |
7 ms |
9720 KB |
answer = YES |
14 |
Correct |
5 ms |
9700 KB |
answer = YES |
15 |
Correct |
5 ms |
9684 KB |
answer = YES |
16 |
Correct |
5 ms |
9684 KB |
answer = YES |
17 |
Correct |
6 ms |
9684 KB |
answer = YES |
18 |
Correct |
5 ms |
9684 KB |
answer = YES |
19 |
Correct |
5 ms |
9684 KB |
answer = YES |
20 |
Correct |
5 ms |
9684 KB |
answer = YES |
21 |
Correct |
5 ms |
9720 KB |
answer = YES |
22 |
Correct |
6 ms |
9684 KB |
answer = NO |
23 |
Correct |
6 ms |
9684 KB |
answer = NO |
24 |
Correct |
6 ms |
9684 KB |
answer = YES |
25 |
Correct |
6 ms |
9684 KB |
answer = YES |
26 |
Correct |
5 ms |
9684 KB |
answer = YES |
27 |
Correct |
6 ms |
9676 KB |
answer = YES |
28 |
Correct |
5 ms |
9684 KB |
answer = YES |
29 |
Correct |
5 ms |
9684 KB |
answer = YES |
30 |
Correct |
5 ms |
9684 KB |
answer = NO |
31 |
Correct |
5 ms |
9696 KB |
answer = YES |
32 |
Correct |
5 ms |
9684 KB |
answer = YES |
33 |
Correct |
5 ms |
9684 KB |
answer = YES |
34 |
Correct |
6 ms |
9684 KB |
answer = YES |
35 |
Correct |
5 ms |
9684 KB |
answer = YES |
36 |
Correct |
6 ms |
9684 KB |
answer = YES |
37 |
Correct |
5 ms |
9684 KB |
answer = YES |
38 |
Correct |
5 ms |
9684 KB |
answer = YES |
39 |
Correct |
6 ms |
9756 KB |
answer = YES |
40 |
Correct |
6 ms |
9812 KB |
answer = YES |
41 |
Correct |
6 ms |
9684 KB |
answer = NO |
42 |
Correct |
7 ms |
9812 KB |
answer = YES |
43 |
Correct |
7 ms |
9812 KB |
answer = YES |
44 |
Correct |
8 ms |
9812 KB |
answer = YES |
45 |
Correct |
6 ms |
9812 KB |
answer = YES |
46 |
Correct |
6 ms |
9684 KB |
answer = YES |
47 |
Correct |
5 ms |
9812 KB |
answer = YES |
48 |
Correct |
6 ms |
9940 KB |
answer = YES |
49 |
Correct |
34 ms |
10612 KB |
answer = YES |
50 |
Correct |
15 ms |
10964 KB |
answer = YES |
51 |
Correct |
24 ms |
10964 KB |
answer = YES |
52 |
Correct |
9 ms |
10228 KB |
answer = NO |
53 |
Correct |
8 ms |
9812 KB |
answer = YES |
54 |
Correct |
10 ms |
9940 KB |
answer = YES |
55 |
Correct |
18 ms |
10196 KB |
answer = YES |
56 |
Correct |
36 ms |
10596 KB |
answer = YES |
57 |
Correct |
27 ms |
10580 KB |
answer = YES |
58 |
Correct |
33 ms |
10448 KB |
answer = YES |
59 |
Correct |
14 ms |
10452 KB |
answer = YES |
60 |
Correct |
37 ms |
10500 KB |
answer = YES |
61 |
Correct |
9 ms |
10196 KB |
answer = YES |
62 |
Correct |
53 ms |
14400 KB |
answer = NO |
63 |
Correct |
60 ms |
15340 KB |
answer = YES |
64 |
Correct |
60 ms |
15052 KB |
answer = NO |
65 |
Correct |
60 ms |
15328 KB |
answer = YES |
66 |
Correct |
9 ms |
9876 KB |
answer = YES |
67 |
Correct |
189 ms |
25372 KB |
answer = YES |
68 |
Correct |
167 ms |
25272 KB |
answer = YES |
69 |
Correct |
89 ms |
25248 KB |
answer = YES |
70 |
Correct |
116 ms |
28388 KB |
answer = YES |
71 |
Correct |
87 ms |
25236 KB |
answer = YES |
72 |
Correct |
396 ms |
18084 KB |
answer = YES |
73 |
Correct |
121 ms |
17996 KB |
answer = YES |
74 |
Correct |
70 ms |
18844 KB |
answer = YES |
75 |
Correct |
30 ms |
14612 KB |
answer = NO |
76 |
Correct |
42 ms |
10792 KB |
answer = YES |
77 |
Correct |
95 ms |
11800 KB |
answer = YES |
78 |
Correct |
149 ms |
13380 KB |
answer = YES |
79 |
Correct |
338 ms |
16900 KB |
answer = YES |
80 |
Correct |
152 ms |
18888 KB |
answer = YES |
81 |
Correct |
42 ms |
18296 KB |
answer = NO |
82 |
Correct |
137 ms |
24644 KB |
answer = YES |
83 |
Correct |
113 ms |
25492 KB |
answer = YES |
84 |
Correct |
288 ms |
25272 KB |
answer = YES |
85 |
Correct |
188 ms |
25468 KB |
answer = YES |
86 |
Correct |
94 ms |
25456 KB |
answer = YES |
87 |
Correct |
52 ms |
16392 KB |
answer = NO |
88 |
Correct |
127 ms |
20928 KB |
answer = YES |
89 |
Correct |
108 ms |
18644 KB |
answer = YES |
90 |
Correct |
103 ms |
18660 KB |
answer = YES |
91 |
Correct |
125 ms |
18668 KB |
answer = YES |
92 |
Correct |
61 ms |
14032 KB |
answer = YES |
93 |
Correct |
81 ms |
14060 KB |
answer = YES |
94 |
Correct |
66 ms |
22252 KB |
answer = NO |
95 |
Correct |
54 ms |
14036 KB |
answer = NO |
96 |
Correct |
254 ms |
26140 KB |
answer = YES |
97 |
Correct |
41 ms |
22256 KB |
answer = NO |