#include <bits/stdc++.h>
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define fe(x, y) for (auto& x : y)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pw(x) (1LL << (x))
using namespace std;
mt19937_64 rng(228);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key
template <typename T>
bool umn(T& a, T b) {
return a > b ? a = b, 1 : 0;
}
template <typename T>
bool umx(T& a, T b) {
return a < b ? a = b, 1 : 0;
}
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;
const int N = 1e5 + 5;
const ld EPS = 1e-10;
bool eq(ld a, ld b) {
return abs(a - b) <= EPS;
}
int n, m;
ve<pii> g[N];
bool vis[N];
int k[N], b[N];
ve<int> st;
ld X = -1e18;
bool found = 0;
ld ans[N];
void dfs(int v, int p) {
vis[v] = 1;
st.pb(v);
// cout << v << " " << k[v] << " " << b[v] << "\n";
fe (to, g[v]) {
if (!vis[to.fi]) {
b[to.fi] = -b[v] + to.se;
k[to.fi] = -k[v];
dfs(to.fi, v);
} else {
int needB = -b[v] + to.se;
int needK = -k[v];
if (mp(b[to.fi], k[to.fi]) == mp(needB, needK)) {
continue;
}
// x * needK + needB = x * k[to.fi] + b[to.fi]
// x * (needK - k[to.fi]) = b[to.fi] - needB
ld nx = ld(b[to.fi] - needB) / (needK - k[to.fi]);
if (found && !eq(nx, X)) {
cout << "NO\n";
exit(0);
}
X = nx;
found = 1;
}
}
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios::sync_with_stdio(0);
cin.tie(0);
#endif
cin >> n >> m;
fr (i, 1, m) {
int a, b, c;
cin >> a >> b >> c;
g[a].pb({b, c});
g[b].pb({a, c});
}
fr (i, 1, n) {
if (!vis[i]) {
st.clear();
k[i] = 1;
X = -1e18;
found = 0;
dfs(i, 0);
if (found) {
fe (cur, st) {
ans[cur] = k[cur] * X + b[cur];
}
} else {
auto eval = [&](ld x) {
ld sum = 0;
fe (cur, st) {
sum += abs(k[cur] * x + b[cur]);
}
return sum;
};
ld l = 0;
ld r = 1e9;
fr (rep, 1, 100) {
ld p1 = l + (r - l) / 3;
ld p2 = r - (r - l) / 3;
if (eval(p1) < eval(p2)) {
r = p2;
} else {
l = p1;
}
}
fe (cur, st) {
ans[cur] = k[cur] * l + b[cur];
}
}
}
}
cout << "YES\n";
cout << fixed << setprecision(8);
fr (i, 1, n) {
cout << ans[i] << " ";
}
cout << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2644 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2684 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2692 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
3 ms |
2644 KB |
answer = YES |
12 |
Correct |
1 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2580 KB |
answer = YES |
14 |
Correct |
2 ms |
2696 KB |
answer = YES |
15 |
Correct |
2 ms |
2684 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
1 ms |
2688 KB |
answer = YES |
19 |
Correct |
2 ms |
2688 KB |
answer = YES |
20 |
Correct |
2 ms |
2644 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
1 ms |
2684 KB |
answer = NO |
23 |
Correct |
1 ms |
2644 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2644 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2684 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2692 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
3 ms |
2644 KB |
answer = YES |
12 |
Correct |
1 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2580 KB |
answer = YES |
14 |
Correct |
2 ms |
2696 KB |
answer = YES |
15 |
Correct |
2 ms |
2684 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
1 ms |
2688 KB |
answer = YES |
19 |
Correct |
2 ms |
2688 KB |
answer = YES |
20 |
Correct |
2 ms |
2644 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
1 ms |
2684 KB |
answer = NO |
23 |
Correct |
1 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
1 ms |
2644 KB |
answer = YES |
26 |
Correct |
1 ms |
2644 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
2 ms |
2644 KB |
answer = YES |
30 |
Correct |
1 ms |
2644 KB |
answer = NO |
31 |
Correct |
2 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2688 KB |
answer = YES |
33 |
Correct |
2 ms |
2688 KB |
answer = YES |
34 |
Correct |
2 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
2 ms |
2644 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2644 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2684 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2692 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
3 ms |
2644 KB |
answer = YES |
12 |
Correct |
1 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2580 KB |
answer = YES |
14 |
Correct |
2 ms |
2696 KB |
answer = YES |
15 |
Correct |
2 ms |
2684 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
1 ms |
2688 KB |
answer = YES |
19 |
Correct |
2 ms |
2688 KB |
answer = YES |
20 |
Correct |
2 ms |
2644 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
1 ms |
2684 KB |
answer = NO |
23 |
Correct |
1 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
1 ms |
2644 KB |
answer = YES |
26 |
Correct |
1 ms |
2644 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
2 ms |
2644 KB |
answer = YES |
30 |
Correct |
1 ms |
2644 KB |
answer = NO |
31 |
Correct |
2 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2688 KB |
answer = YES |
33 |
Correct |
2 ms |
2688 KB |
answer = YES |
34 |
Correct |
2 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
2 ms |
2644 KB |
answer = YES |
37 |
Correct |
2 ms |
2644 KB |
answer = YES |
38 |
Correct |
2 ms |
2604 KB |
answer = YES |
39 |
Correct |
2 ms |
2644 KB |
answer = YES |
40 |
Correct |
2 ms |
2772 KB |
answer = YES |
41 |
Correct |
2 ms |
2644 KB |
answer = NO |
42 |
Correct |
2 ms |
2700 KB |
answer = YES |
43 |
Correct |
3 ms |
2772 KB |
answer = YES |
44 |
Incorrect |
3 ms |
2772 KB |
participant answer is larger than the answer of jury |
45 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2644 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2684 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2692 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
3 ms |
2644 KB |
answer = YES |
12 |
Correct |
1 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2580 KB |
answer = YES |
14 |
Correct |
2 ms |
2696 KB |
answer = YES |
15 |
Correct |
2 ms |
2684 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
1 ms |
2688 KB |
answer = YES |
19 |
Correct |
2 ms |
2688 KB |
answer = YES |
20 |
Correct |
2 ms |
2644 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
1 ms |
2684 KB |
answer = NO |
23 |
Correct |
1 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
1 ms |
2644 KB |
answer = YES |
26 |
Correct |
1 ms |
2644 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
2 ms |
2644 KB |
answer = YES |
30 |
Correct |
1 ms |
2644 KB |
answer = NO |
31 |
Correct |
2 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2688 KB |
answer = YES |
33 |
Correct |
2 ms |
2688 KB |
answer = YES |
34 |
Correct |
2 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
2 ms |
2644 KB |
answer = YES |
37 |
Correct |
2 ms |
2644 KB |
answer = YES |
38 |
Correct |
2 ms |
2604 KB |
answer = YES |
39 |
Correct |
2 ms |
2644 KB |
answer = YES |
40 |
Correct |
2 ms |
2772 KB |
answer = YES |
41 |
Correct |
2 ms |
2644 KB |
answer = NO |
42 |
Correct |
2 ms |
2700 KB |
answer = YES |
43 |
Correct |
3 ms |
2772 KB |
answer = YES |
44 |
Incorrect |
3 ms |
2772 KB |
participant answer is larger than the answer of jury |
45 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2644 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2684 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2692 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
3 ms |
2644 KB |
answer = YES |
12 |
Correct |
1 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2580 KB |
answer = YES |
14 |
Correct |
2 ms |
2696 KB |
answer = YES |
15 |
Correct |
2 ms |
2684 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
1 ms |
2688 KB |
answer = YES |
19 |
Correct |
2 ms |
2688 KB |
answer = YES |
20 |
Correct |
2 ms |
2644 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
1 ms |
2684 KB |
answer = NO |
23 |
Correct |
1 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
1 ms |
2644 KB |
answer = YES |
26 |
Correct |
1 ms |
2644 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
2 ms |
2644 KB |
answer = YES |
30 |
Correct |
1 ms |
2644 KB |
answer = NO |
31 |
Correct |
2 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2688 KB |
answer = YES |
33 |
Correct |
2 ms |
2688 KB |
answer = YES |
34 |
Correct |
2 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
2 ms |
2644 KB |
answer = YES |
37 |
Correct |
2 ms |
2644 KB |
answer = YES |
38 |
Correct |
2 ms |
2604 KB |
answer = YES |
39 |
Correct |
2 ms |
2644 KB |
answer = YES |
40 |
Correct |
2 ms |
2772 KB |
answer = YES |
41 |
Correct |
2 ms |
2644 KB |
answer = NO |
42 |
Correct |
2 ms |
2700 KB |
answer = YES |
43 |
Correct |
3 ms |
2772 KB |
answer = YES |
44 |
Incorrect |
3 ms |
2772 KB |
participant answer is larger than the answer of jury |
45 |
Halted |
0 ms |
0 KB |
- |