// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
using db = long double;
const int INF = 1e9;
const int B = 1e8;
const db EPS = 1e-11;
const db BEPS = 3e-8;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, M; cin >> N >> M;
V<vpi> adj(N); for(int i = 0; i < M; i++) {
int u, v, w; cin >> u >> v >> w; --u, --v;
adj[u].pb(mp(v, w));
adj[v].pb(mp(u, w));
}
auto C = [&](pi p, int w) {
// cout << p.f << " " << p.s << " " << w << endl;
return mp(w - p.f, -p.s);
};
cout << fixed << setprecision(10);
vi vis(N), COMP; V<set<pi>> S(N);
function<void(int)> dfs = [&](int u) {
vis[u] = 1; COMP.pb(u);
pi p = *begin(S[u]);
// cout << u << " => " << p.f << " " << p.s << endl;
for(auto& e : adj[u]) {
int v, w; tie(v, w) = e;
// cout << v << " " << w << endl;
S[v].insert(C(p, w));
if (!vis[v]) dfs(v);
}
};
V<db> ans(N, INF);
function<void(int)> get = [&](int u) {
// cout << u << endl;
for(auto& e : adj[u]) {
int v, w; tie(v, w) = e;
// cout << u << " => " << v << endl;
// cout << ans[u] << " -> " << ans[v] << endl;
db x = w - ans[u];
if (ans[v] > B) {
ans[v] = x; get(v);
} else {
if (abs(ans[v] - x) > EPS) {
cout << "NO" << nl;
exit(0-0);
}
}
}
};
for(int r = 0; r < N; r++) if (!vis[r]) {
COMP = {}; S[r].insert(mp(0, 1)); dfs(r);
// cout << endl << endl;
db x = INF; int R = -1;
for(auto& i : COMP) if (sz(S[i]) >= 2) {
// cout << i << endl;
vi pos, neg; for(auto& p : S[i]) {
// cout << p.f << " " << p.s << endl;
if (p.s == -1) neg.pb(p.f);
else pos.pb(p.f);
}
if (max(sz(pos), sz(neg)) > 1) {
cout << "NO" << nl;
exit(0-0);
}
x = db(pos.back() + neg.back()) / db(2);
// cout << x << endl;
R = i;
// cout << "DONE" << endl;
break;
}
if (R == -1) {
// cout << "R: " << r << endl;
db bst = -INF, val = INF;
auto check = [&](db x) {
ans[r] = x; get(r);
db cost = 0; for(auto& i : COMP) cost += abs(ans[i]), ans[i] = INF;
// cout << x << " => " << cost << endl;
if (cost + EPS < val) bst = x, val = cost;
return cost;
};
db lo = -INF, hi = INF;
for(int t = 0; t < 200; t++) {
db mid = (lo + hi) / 2;
if (check(mid) < check(mid + BEPS)) hi = mid;
else lo = mid;
}
// cout << bst << endl;
ans[r] = bst; get(r);
} else {
ans[R] = x; get(R);
}
}
cout << "YES" << nl;
for(auto& x : ans) cout << x << " ";
cout << nl;
exit(0-0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
answer = YES |
2 |
Correct |
0 ms |
344 KB |
answer = YES |
3 |
Correct |
0 ms |
344 KB |
answer = YES |
4 |
Correct |
0 ms |
348 KB |
answer = NO |
5 |
Correct |
0 ms |
348 KB |
answer = YES |
6 |
Correct |
0 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
348 KB |
answer = YES |
8 |
Correct |
1 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
348 KB |
answer = NO |
10 |
Correct |
0 ms |
348 KB |
answer = YES |
11 |
Correct |
0 ms |
348 KB |
answer = YES |
12 |
Correct |
0 ms |
412 KB |
answer = NO |
13 |
Correct |
0 ms |
344 KB |
answer = YES |
14 |
Correct |
0 ms |
348 KB |
answer = YES |
15 |
Correct |
0 ms |
348 KB |
answer = YES |
16 |
Correct |
0 ms |
348 KB |
answer = YES |
17 |
Correct |
1 ms |
348 KB |
answer = YES |
18 |
Correct |
0 ms |
348 KB |
answer = YES |
19 |
Correct |
1 ms |
348 KB |
answer = YES |
20 |
Correct |
0 ms |
344 KB |
answer = YES |
21 |
Correct |
1 ms |
344 KB |
answer = YES |
22 |
Correct |
1 ms |
348 KB |
answer = NO |
23 |
Correct |
0 ms |
348 KB |
answer = NO |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
answer = YES |
2 |
Correct |
0 ms |
344 KB |
answer = YES |
3 |
Correct |
0 ms |
344 KB |
answer = YES |
4 |
Correct |
0 ms |
348 KB |
answer = NO |
5 |
Correct |
0 ms |
348 KB |
answer = YES |
6 |
Correct |
0 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
348 KB |
answer = YES |
8 |
Correct |
1 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
348 KB |
answer = NO |
10 |
Correct |
0 ms |
348 KB |
answer = YES |
11 |
Correct |
0 ms |
348 KB |
answer = YES |
12 |
Correct |
0 ms |
412 KB |
answer = NO |
13 |
Correct |
0 ms |
344 KB |
answer = YES |
14 |
Correct |
0 ms |
348 KB |
answer = YES |
15 |
Correct |
0 ms |
348 KB |
answer = YES |
16 |
Correct |
0 ms |
348 KB |
answer = YES |
17 |
Correct |
1 ms |
348 KB |
answer = YES |
18 |
Correct |
0 ms |
348 KB |
answer = YES |
19 |
Correct |
1 ms |
348 KB |
answer = YES |
20 |
Correct |
0 ms |
344 KB |
answer = YES |
21 |
Correct |
1 ms |
344 KB |
answer = YES |
22 |
Correct |
1 ms |
348 KB |
answer = NO |
23 |
Correct |
0 ms |
348 KB |
answer = NO |
24 |
Correct |
1 ms |
348 KB |
answer = YES |
25 |
Correct |
1 ms |
348 KB |
answer = YES |
26 |
Correct |
1 ms |
348 KB |
answer = YES |
27 |
Correct |
0 ms |
348 KB |
answer = YES |
28 |
Correct |
1 ms |
348 KB |
answer = YES |
29 |
Correct |
1 ms |
348 KB |
answer = YES |
30 |
Correct |
1 ms |
344 KB |
answer = NO |
31 |
Correct |
1 ms |
348 KB |
answer = YES |
32 |
Correct |
0 ms |
348 KB |
answer = YES |
33 |
Correct |
2 ms |
512 KB |
answer = YES |
34 |
Correct |
1 ms |
600 KB |
answer = YES |
35 |
Correct |
0 ms |
348 KB |
answer = YES |
36 |
Correct |
1 ms |
348 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
answer = YES |
2 |
Correct |
0 ms |
344 KB |
answer = YES |
3 |
Correct |
0 ms |
344 KB |
answer = YES |
4 |
Correct |
0 ms |
348 KB |
answer = NO |
5 |
Correct |
0 ms |
348 KB |
answer = YES |
6 |
Correct |
0 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
348 KB |
answer = YES |
8 |
Correct |
1 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
348 KB |
answer = NO |
10 |
Correct |
0 ms |
348 KB |
answer = YES |
11 |
Correct |
0 ms |
348 KB |
answer = YES |
12 |
Correct |
0 ms |
412 KB |
answer = NO |
13 |
Correct |
0 ms |
344 KB |
answer = YES |
14 |
Correct |
0 ms |
348 KB |
answer = YES |
15 |
Correct |
0 ms |
348 KB |
answer = YES |
16 |
Correct |
0 ms |
348 KB |
answer = YES |
17 |
Correct |
1 ms |
348 KB |
answer = YES |
18 |
Correct |
0 ms |
348 KB |
answer = YES |
19 |
Correct |
1 ms |
348 KB |
answer = YES |
20 |
Correct |
0 ms |
344 KB |
answer = YES |
21 |
Correct |
1 ms |
344 KB |
answer = YES |
22 |
Correct |
1 ms |
348 KB |
answer = NO |
23 |
Correct |
0 ms |
348 KB |
answer = NO |
24 |
Correct |
1 ms |
348 KB |
answer = YES |
25 |
Correct |
1 ms |
348 KB |
answer = YES |
26 |
Correct |
1 ms |
348 KB |
answer = YES |
27 |
Correct |
0 ms |
348 KB |
answer = YES |
28 |
Correct |
1 ms |
348 KB |
answer = YES |
29 |
Correct |
1 ms |
348 KB |
answer = YES |
30 |
Correct |
1 ms |
344 KB |
answer = NO |
31 |
Correct |
1 ms |
348 KB |
answer = YES |
32 |
Correct |
0 ms |
348 KB |
answer = YES |
33 |
Correct |
2 ms |
512 KB |
answer = YES |
34 |
Correct |
1 ms |
600 KB |
answer = YES |
35 |
Correct |
0 ms |
348 KB |
answer = YES |
36 |
Correct |
1 ms |
348 KB |
answer = YES |
37 |
Correct |
2 ms |
344 KB |
answer = YES |
38 |
Correct |
1 ms |
348 KB |
answer = YES |
39 |
Correct |
4 ms |
348 KB |
answer = YES |
40 |
Correct |
1 ms |
604 KB |
answer = YES |
41 |
Correct |
1 ms |
604 KB |
answer = NO |
42 |
Correct |
8 ms |
604 KB |
answer = YES |
43 |
Correct |
10 ms |
604 KB |
answer = YES |
44 |
Correct |
9 ms |
604 KB |
answer = YES |
45 |
Correct |
1 ms |
604 KB |
answer = YES |
46 |
Correct |
4 ms |
348 KB |
answer = YES |
47 |
Correct |
1 ms |
600 KB |
answer = YES |
48 |
Correct |
1 ms |
604 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
answer = YES |
2 |
Correct |
0 ms |
344 KB |
answer = YES |
3 |
Correct |
0 ms |
344 KB |
answer = YES |
4 |
Correct |
0 ms |
348 KB |
answer = NO |
5 |
Correct |
0 ms |
348 KB |
answer = YES |
6 |
Correct |
0 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
348 KB |
answer = YES |
8 |
Correct |
1 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
348 KB |
answer = NO |
10 |
Correct |
0 ms |
348 KB |
answer = YES |
11 |
Correct |
0 ms |
348 KB |
answer = YES |
12 |
Correct |
0 ms |
412 KB |
answer = NO |
13 |
Correct |
0 ms |
344 KB |
answer = YES |
14 |
Correct |
0 ms |
348 KB |
answer = YES |
15 |
Correct |
0 ms |
348 KB |
answer = YES |
16 |
Correct |
0 ms |
348 KB |
answer = YES |
17 |
Correct |
1 ms |
348 KB |
answer = YES |
18 |
Correct |
0 ms |
348 KB |
answer = YES |
19 |
Correct |
1 ms |
348 KB |
answer = YES |
20 |
Correct |
0 ms |
344 KB |
answer = YES |
21 |
Correct |
1 ms |
344 KB |
answer = YES |
22 |
Correct |
1 ms |
348 KB |
answer = NO |
23 |
Correct |
0 ms |
348 KB |
answer = NO |
24 |
Correct |
1 ms |
348 KB |
answer = YES |
25 |
Correct |
1 ms |
348 KB |
answer = YES |
26 |
Correct |
1 ms |
348 KB |
answer = YES |
27 |
Correct |
0 ms |
348 KB |
answer = YES |
28 |
Correct |
1 ms |
348 KB |
answer = YES |
29 |
Correct |
1 ms |
348 KB |
answer = YES |
30 |
Correct |
1 ms |
344 KB |
answer = NO |
31 |
Correct |
1 ms |
348 KB |
answer = YES |
32 |
Correct |
0 ms |
348 KB |
answer = YES |
33 |
Correct |
2 ms |
512 KB |
answer = YES |
34 |
Correct |
1 ms |
600 KB |
answer = YES |
35 |
Correct |
0 ms |
348 KB |
answer = YES |
36 |
Correct |
1 ms |
348 KB |
answer = YES |
37 |
Correct |
2 ms |
344 KB |
answer = YES |
38 |
Correct |
1 ms |
348 KB |
answer = YES |
39 |
Correct |
4 ms |
348 KB |
answer = YES |
40 |
Correct |
1 ms |
604 KB |
answer = YES |
41 |
Correct |
1 ms |
604 KB |
answer = NO |
42 |
Correct |
8 ms |
604 KB |
answer = YES |
43 |
Correct |
10 ms |
604 KB |
answer = YES |
44 |
Correct |
9 ms |
604 KB |
answer = YES |
45 |
Correct |
1 ms |
604 KB |
answer = YES |
46 |
Correct |
4 ms |
348 KB |
answer = YES |
47 |
Correct |
1 ms |
600 KB |
answer = YES |
48 |
Correct |
1 ms |
604 KB |
answer = YES |
49 |
Correct |
137 ms |
2248 KB |
answer = YES |
50 |
Correct |
8 ms |
2908 KB |
answer = YES |
51 |
Correct |
102 ms |
2896 KB |
answer = YES |
52 |
Correct |
4 ms |
2648 KB |
answer = NO |
53 |
Correct |
8 ms |
604 KB |
answer = YES |
54 |
Correct |
20 ms |
856 KB |
answer = YES |
55 |
Incorrect |
54 ms |
1376 KB |
participant answer is larger than the answer of jury |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
answer = YES |
2 |
Correct |
0 ms |
344 KB |
answer = YES |
3 |
Correct |
0 ms |
344 KB |
answer = YES |
4 |
Correct |
0 ms |
348 KB |
answer = NO |
5 |
Correct |
0 ms |
348 KB |
answer = YES |
6 |
Correct |
0 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
348 KB |
answer = YES |
8 |
Correct |
1 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
348 KB |
answer = NO |
10 |
Correct |
0 ms |
348 KB |
answer = YES |
11 |
Correct |
0 ms |
348 KB |
answer = YES |
12 |
Correct |
0 ms |
412 KB |
answer = NO |
13 |
Correct |
0 ms |
344 KB |
answer = YES |
14 |
Correct |
0 ms |
348 KB |
answer = YES |
15 |
Correct |
0 ms |
348 KB |
answer = YES |
16 |
Correct |
0 ms |
348 KB |
answer = YES |
17 |
Correct |
1 ms |
348 KB |
answer = YES |
18 |
Correct |
0 ms |
348 KB |
answer = YES |
19 |
Correct |
1 ms |
348 KB |
answer = YES |
20 |
Correct |
0 ms |
344 KB |
answer = YES |
21 |
Correct |
1 ms |
344 KB |
answer = YES |
22 |
Correct |
1 ms |
348 KB |
answer = NO |
23 |
Correct |
0 ms |
348 KB |
answer = NO |
24 |
Correct |
1 ms |
348 KB |
answer = YES |
25 |
Correct |
1 ms |
348 KB |
answer = YES |
26 |
Correct |
1 ms |
348 KB |
answer = YES |
27 |
Correct |
0 ms |
348 KB |
answer = YES |
28 |
Correct |
1 ms |
348 KB |
answer = YES |
29 |
Correct |
1 ms |
348 KB |
answer = YES |
30 |
Correct |
1 ms |
344 KB |
answer = NO |
31 |
Correct |
1 ms |
348 KB |
answer = YES |
32 |
Correct |
0 ms |
348 KB |
answer = YES |
33 |
Correct |
2 ms |
512 KB |
answer = YES |
34 |
Correct |
1 ms |
600 KB |
answer = YES |
35 |
Correct |
0 ms |
348 KB |
answer = YES |
36 |
Correct |
1 ms |
348 KB |
answer = YES |
37 |
Correct |
2 ms |
344 KB |
answer = YES |
38 |
Correct |
1 ms |
348 KB |
answer = YES |
39 |
Correct |
4 ms |
348 KB |
answer = YES |
40 |
Correct |
1 ms |
604 KB |
answer = YES |
41 |
Correct |
1 ms |
604 KB |
answer = NO |
42 |
Correct |
8 ms |
604 KB |
answer = YES |
43 |
Correct |
10 ms |
604 KB |
answer = YES |
44 |
Correct |
9 ms |
604 KB |
answer = YES |
45 |
Correct |
1 ms |
604 KB |
answer = YES |
46 |
Correct |
4 ms |
348 KB |
answer = YES |
47 |
Correct |
1 ms |
600 KB |
answer = YES |
48 |
Correct |
1 ms |
604 KB |
answer = YES |
49 |
Correct |
137 ms |
2248 KB |
answer = YES |
50 |
Correct |
8 ms |
2908 KB |
answer = YES |
51 |
Correct |
102 ms |
2896 KB |
answer = YES |
52 |
Correct |
4 ms |
2648 KB |
answer = NO |
53 |
Correct |
8 ms |
604 KB |
answer = YES |
54 |
Correct |
20 ms |
856 KB |
answer = YES |
55 |
Incorrect |
54 ms |
1376 KB |
participant answer is larger than the answer of jury |
56 |
Halted |
0 ms |
0 KB |
- |