#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
vector<pll> adj[N];
vector<bool> vis(N);
vector<pll> val(N);
vector<ll> curr_nodes;
pll fix = {-1,-1};
bool ok = true;
void dfs1(ll u){
if(fix.ff != -1) return;
curr_nodes.pb(u);
vis[u] = 1;
for(auto [v,w] : adj[u]){
if(fix.ff != -1) return;
pll want = {-val[u].ff,w-val[u].ss};
if(vis[v]){
if(want != val[v]){
if(want.ff == val[v].ff){
ok = false;
}
else{
auto p1 = want, p2 = val[v];
if(p1.ff != 1) swap(p1,p2);
assert(p1.ff == 1);
assert(p2.ff == -1);
ll x = p2.ss-p1.ss;
fix = {v,x};
return;
}
}
}
else{
val[v] = want;
dfs1(v);
}
}
}
vector<ll> ans(N);
void dfs2(ll u){
vis[u] = 1;
for(auto [v,w] : adj[u]){
ll want = w*2-ans[u];
if(vis[v]){
if(ans[v] != want){
ok = false;
}
}
else{
ans[v] = want;
dfs2(v);
}
}
}
void solve(int test_case)
{
ll n,m; cin >> n >> m;
rep1(i,m){
ll u,v,w; cin >> u >> v >> w;
adj[u].pb({v,w}), adj[v].pb({u,w});
}
rep1(i,n){
if(vis[i]) conts;
curr_nodes.clear();
fix = {-1,-1};
val[i] = {1,0};
dfs1(i);
if(fix.ff != -1){
trav(u,curr_nodes){
vis[u] = 0;
}
curr_nodes.clear();
ans[i] = fix.ss;
dfs2(i);
conts;
}
vector<pll> vals;
trav(u,curr_nodes){
vis[u] = 0;
vals.pb(val[u]);
}
pll best = {inf2,inf2};
for(auto [k1,k2] : vals){
ll x = -k2/k1;
ll sum = 0;
for(auto [k3,k4] : vals){
sum += abs(k3*x+k4);
}
pll px = {sum,x};
amin(best,px);
}
ans[i] = best.ss*2;
dfs2(i);
}
if(!ok){
no;
return;
}
cout << fixed << setprecision(11);
yes;
rep1(i,n) cout << (ld)ans[i]/2 << " ";
cout << endl;
}
int main()
{
fastio;
int t = 1;
// cin >> t;
rep1(i, t) {
solve(i);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4960 KB |
answer = YES |
2 |
Correct |
2 ms |
4956 KB |
answer = YES |
3 |
Correct |
2 ms |
4952 KB |
answer = YES |
4 |
Correct |
2 ms |
4956 KB |
answer = NO |
5 |
Correct |
2 ms |
4956 KB |
answer = YES |
6 |
Correct |
3 ms |
4956 KB |
answer = YES |
7 |
Correct |
2 ms |
4956 KB |
answer = YES |
8 |
Correct |
2 ms |
4956 KB |
answer = YES |
9 |
Correct |
2 ms |
4960 KB |
answer = NO |
10 |
Correct |
2 ms |
4968 KB |
answer = YES |
11 |
Correct |
2 ms |
4968 KB |
answer = YES |
12 |
Correct |
2 ms |
4968 KB |
answer = NO |
13 |
Correct |
2 ms |
4968 KB |
answer = YES |
14 |
Correct |
2 ms |
5192 KB |
answer = YES |
15 |
Correct |
2 ms |
4956 KB |
answer = YES |
16 |
Correct |
2 ms |
4956 KB |
answer = YES |
17 |
Correct |
2 ms |
4956 KB |
answer = YES |
18 |
Correct |
2 ms |
4952 KB |
answer = YES |
19 |
Correct |
2 ms |
4956 KB |
answer = YES |
20 |
Correct |
2 ms |
4956 KB |
answer = YES |
21 |
Correct |
2 ms |
4956 KB |
answer = YES |
22 |
Correct |
3 ms |
4956 KB |
answer = NO |
23 |
Correct |
2 ms |
4952 KB |
answer = NO |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4960 KB |
answer = YES |
2 |
Correct |
2 ms |
4956 KB |
answer = YES |
3 |
Correct |
2 ms |
4952 KB |
answer = YES |
4 |
Correct |
2 ms |
4956 KB |
answer = NO |
5 |
Correct |
2 ms |
4956 KB |
answer = YES |
6 |
Correct |
3 ms |
4956 KB |
answer = YES |
7 |
Correct |
2 ms |
4956 KB |
answer = YES |
8 |
Correct |
2 ms |
4956 KB |
answer = YES |
9 |
Correct |
2 ms |
4960 KB |
answer = NO |
10 |
Correct |
2 ms |
4968 KB |
answer = YES |
11 |
Correct |
2 ms |
4968 KB |
answer = YES |
12 |
Correct |
2 ms |
4968 KB |
answer = NO |
13 |
Correct |
2 ms |
4968 KB |
answer = YES |
14 |
Correct |
2 ms |
5192 KB |
answer = YES |
15 |
Correct |
2 ms |
4956 KB |
answer = YES |
16 |
Correct |
2 ms |
4956 KB |
answer = YES |
17 |
Correct |
2 ms |
4956 KB |
answer = YES |
18 |
Correct |
2 ms |
4952 KB |
answer = YES |
19 |
Correct |
2 ms |
4956 KB |
answer = YES |
20 |
Correct |
2 ms |
4956 KB |
answer = YES |
21 |
Correct |
2 ms |
4956 KB |
answer = YES |
22 |
Correct |
3 ms |
4956 KB |
answer = NO |
23 |
Correct |
2 ms |
4952 KB |
answer = NO |
24 |
Correct |
2 ms |
5180 KB |
answer = YES |
25 |
Correct |
2 ms |
4956 KB |
answer = YES |
26 |
Correct |
2 ms |
4956 KB |
answer = YES |
27 |
Correct |
2 ms |
4968 KB |
answer = YES |
28 |
Correct |
3 ms |
4968 KB |
answer = YES |
29 |
Correct |
2 ms |
4968 KB |
answer = YES |
30 |
Correct |
2 ms |
4968 KB |
answer = NO |
31 |
Correct |
2 ms |
4968 KB |
answer = YES |
32 |
Correct |
2 ms |
5204 KB |
answer = YES |
33 |
Correct |
2 ms |
4968 KB |
answer = YES |
34 |
Correct |
2 ms |
4968 KB |
answer = YES |
35 |
Correct |
2 ms |
4968 KB |
answer = YES |
36 |
Correct |
2 ms |
4968 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4960 KB |
answer = YES |
2 |
Correct |
2 ms |
4956 KB |
answer = YES |
3 |
Correct |
2 ms |
4952 KB |
answer = YES |
4 |
Correct |
2 ms |
4956 KB |
answer = NO |
5 |
Correct |
2 ms |
4956 KB |
answer = YES |
6 |
Correct |
3 ms |
4956 KB |
answer = YES |
7 |
Correct |
2 ms |
4956 KB |
answer = YES |
8 |
Correct |
2 ms |
4956 KB |
answer = YES |
9 |
Correct |
2 ms |
4960 KB |
answer = NO |
10 |
Correct |
2 ms |
4968 KB |
answer = YES |
11 |
Correct |
2 ms |
4968 KB |
answer = YES |
12 |
Correct |
2 ms |
4968 KB |
answer = NO |
13 |
Correct |
2 ms |
4968 KB |
answer = YES |
14 |
Correct |
2 ms |
5192 KB |
answer = YES |
15 |
Correct |
2 ms |
4956 KB |
answer = YES |
16 |
Correct |
2 ms |
4956 KB |
answer = YES |
17 |
Correct |
2 ms |
4956 KB |
answer = YES |
18 |
Correct |
2 ms |
4952 KB |
answer = YES |
19 |
Correct |
2 ms |
4956 KB |
answer = YES |
20 |
Correct |
2 ms |
4956 KB |
answer = YES |
21 |
Correct |
2 ms |
4956 KB |
answer = YES |
22 |
Correct |
3 ms |
4956 KB |
answer = NO |
23 |
Correct |
2 ms |
4952 KB |
answer = NO |
24 |
Correct |
2 ms |
5180 KB |
answer = YES |
25 |
Correct |
2 ms |
4956 KB |
answer = YES |
26 |
Correct |
2 ms |
4956 KB |
answer = YES |
27 |
Correct |
2 ms |
4968 KB |
answer = YES |
28 |
Correct |
3 ms |
4968 KB |
answer = YES |
29 |
Correct |
2 ms |
4968 KB |
answer = YES |
30 |
Correct |
2 ms |
4968 KB |
answer = NO |
31 |
Correct |
2 ms |
4968 KB |
answer = YES |
32 |
Correct |
2 ms |
5204 KB |
answer = YES |
33 |
Correct |
2 ms |
4968 KB |
answer = YES |
34 |
Correct |
2 ms |
4968 KB |
answer = YES |
35 |
Correct |
2 ms |
4968 KB |
answer = YES |
36 |
Correct |
2 ms |
4968 KB |
answer = YES |
37 |
Correct |
2 ms |
4968 KB |
answer = YES |
38 |
Correct |
2 ms |
4968 KB |
answer = YES |
39 |
Correct |
4 ms |
5224 KB |
answer = YES |
40 |
Correct |
2 ms |
5224 KB |
answer = YES |
41 |
Correct |
3 ms |
5224 KB |
answer = NO |
42 |
Correct |
3 ms |
5224 KB |
answer = YES |
43 |
Correct |
3 ms |
5224 KB |
answer = YES |
44 |
Correct |
2 ms |
5224 KB |
answer = YES |
45 |
Correct |
3 ms |
5212 KB |
answer = YES |
46 |
Correct |
3 ms |
5212 KB |
answer = YES |
47 |
Correct |
3 ms |
5204 KB |
answer = YES |
48 |
Correct |
2 ms |
5252 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4960 KB |
answer = YES |
2 |
Correct |
2 ms |
4956 KB |
answer = YES |
3 |
Correct |
2 ms |
4952 KB |
answer = YES |
4 |
Correct |
2 ms |
4956 KB |
answer = NO |
5 |
Correct |
2 ms |
4956 KB |
answer = YES |
6 |
Correct |
3 ms |
4956 KB |
answer = YES |
7 |
Correct |
2 ms |
4956 KB |
answer = YES |
8 |
Correct |
2 ms |
4956 KB |
answer = YES |
9 |
Correct |
2 ms |
4960 KB |
answer = NO |
10 |
Correct |
2 ms |
4968 KB |
answer = YES |
11 |
Correct |
2 ms |
4968 KB |
answer = YES |
12 |
Correct |
2 ms |
4968 KB |
answer = NO |
13 |
Correct |
2 ms |
4968 KB |
answer = YES |
14 |
Correct |
2 ms |
5192 KB |
answer = YES |
15 |
Correct |
2 ms |
4956 KB |
answer = YES |
16 |
Correct |
2 ms |
4956 KB |
answer = YES |
17 |
Correct |
2 ms |
4956 KB |
answer = YES |
18 |
Correct |
2 ms |
4952 KB |
answer = YES |
19 |
Correct |
2 ms |
4956 KB |
answer = YES |
20 |
Correct |
2 ms |
4956 KB |
answer = YES |
21 |
Correct |
2 ms |
4956 KB |
answer = YES |
22 |
Correct |
3 ms |
4956 KB |
answer = NO |
23 |
Correct |
2 ms |
4952 KB |
answer = NO |
24 |
Correct |
2 ms |
5180 KB |
answer = YES |
25 |
Correct |
2 ms |
4956 KB |
answer = YES |
26 |
Correct |
2 ms |
4956 KB |
answer = YES |
27 |
Correct |
2 ms |
4968 KB |
answer = YES |
28 |
Correct |
3 ms |
4968 KB |
answer = YES |
29 |
Correct |
2 ms |
4968 KB |
answer = YES |
30 |
Correct |
2 ms |
4968 KB |
answer = NO |
31 |
Correct |
2 ms |
4968 KB |
answer = YES |
32 |
Correct |
2 ms |
5204 KB |
answer = YES |
33 |
Correct |
2 ms |
4968 KB |
answer = YES |
34 |
Correct |
2 ms |
4968 KB |
answer = YES |
35 |
Correct |
2 ms |
4968 KB |
answer = YES |
36 |
Correct |
2 ms |
4968 KB |
answer = YES |
37 |
Correct |
2 ms |
4968 KB |
answer = YES |
38 |
Correct |
2 ms |
4968 KB |
answer = YES |
39 |
Correct |
4 ms |
5224 KB |
answer = YES |
40 |
Correct |
2 ms |
5224 KB |
answer = YES |
41 |
Correct |
3 ms |
5224 KB |
answer = NO |
42 |
Correct |
3 ms |
5224 KB |
answer = YES |
43 |
Correct |
3 ms |
5224 KB |
answer = YES |
44 |
Correct |
2 ms |
5224 KB |
answer = YES |
45 |
Correct |
3 ms |
5212 KB |
answer = YES |
46 |
Correct |
3 ms |
5212 KB |
answer = YES |
47 |
Correct |
3 ms |
5204 KB |
answer = YES |
48 |
Correct |
2 ms |
5252 KB |
answer = YES |
49 |
Correct |
108 ms |
6240 KB |
answer = YES |
50 |
Correct |
9 ms |
6232 KB |
answer = YES |
51 |
Correct |
98 ms |
6504 KB |
answer = YES |
52 |
Correct |
96 ms |
6496 KB |
answer = NO |
53 |
Correct |
3 ms |
5208 KB |
answer = YES |
54 |
Correct |
9 ms |
5464 KB |
answer = YES |
55 |
Correct |
32 ms |
5736 KB |
answer = YES |
56 |
Correct |
103 ms |
6248 KB |
answer = YES |
57 |
Correct |
22 ms |
5916 KB |
answer = YES |
58 |
Correct |
41 ms |
5976 KB |
answer = YES |
59 |
Correct |
12 ms |
5724 KB |
answer = YES |
60 |
Correct |
51 ms |
5984 KB |
answer = YES |
61 |
Correct |
6 ms |
5464 KB |
answer = YES |
62 |
Correct |
71 ms |
16884 KB |
answer = NO |
63 |
Correct |
75 ms |
16976 KB |
answer = YES |
64 |
Correct |
56 ms |
16712 KB |
answer = NO |
65 |
Correct |
77 ms |
16976 KB |
answer = YES |
66 |
Correct |
7 ms |
5212 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4960 KB |
answer = YES |
2 |
Correct |
2 ms |
4956 KB |
answer = YES |
3 |
Correct |
2 ms |
4952 KB |
answer = YES |
4 |
Correct |
2 ms |
4956 KB |
answer = NO |
5 |
Correct |
2 ms |
4956 KB |
answer = YES |
6 |
Correct |
3 ms |
4956 KB |
answer = YES |
7 |
Correct |
2 ms |
4956 KB |
answer = YES |
8 |
Correct |
2 ms |
4956 KB |
answer = YES |
9 |
Correct |
2 ms |
4960 KB |
answer = NO |
10 |
Correct |
2 ms |
4968 KB |
answer = YES |
11 |
Correct |
2 ms |
4968 KB |
answer = YES |
12 |
Correct |
2 ms |
4968 KB |
answer = NO |
13 |
Correct |
2 ms |
4968 KB |
answer = YES |
14 |
Correct |
2 ms |
5192 KB |
answer = YES |
15 |
Correct |
2 ms |
4956 KB |
answer = YES |
16 |
Correct |
2 ms |
4956 KB |
answer = YES |
17 |
Correct |
2 ms |
4956 KB |
answer = YES |
18 |
Correct |
2 ms |
4952 KB |
answer = YES |
19 |
Correct |
2 ms |
4956 KB |
answer = YES |
20 |
Correct |
2 ms |
4956 KB |
answer = YES |
21 |
Correct |
2 ms |
4956 KB |
answer = YES |
22 |
Correct |
3 ms |
4956 KB |
answer = NO |
23 |
Correct |
2 ms |
4952 KB |
answer = NO |
24 |
Correct |
2 ms |
5180 KB |
answer = YES |
25 |
Correct |
2 ms |
4956 KB |
answer = YES |
26 |
Correct |
2 ms |
4956 KB |
answer = YES |
27 |
Correct |
2 ms |
4968 KB |
answer = YES |
28 |
Correct |
3 ms |
4968 KB |
answer = YES |
29 |
Correct |
2 ms |
4968 KB |
answer = YES |
30 |
Correct |
2 ms |
4968 KB |
answer = NO |
31 |
Correct |
2 ms |
4968 KB |
answer = YES |
32 |
Correct |
2 ms |
5204 KB |
answer = YES |
33 |
Correct |
2 ms |
4968 KB |
answer = YES |
34 |
Correct |
2 ms |
4968 KB |
answer = YES |
35 |
Correct |
2 ms |
4968 KB |
answer = YES |
36 |
Correct |
2 ms |
4968 KB |
answer = YES |
37 |
Correct |
2 ms |
4968 KB |
answer = YES |
38 |
Correct |
2 ms |
4968 KB |
answer = YES |
39 |
Correct |
4 ms |
5224 KB |
answer = YES |
40 |
Correct |
2 ms |
5224 KB |
answer = YES |
41 |
Correct |
3 ms |
5224 KB |
answer = NO |
42 |
Correct |
3 ms |
5224 KB |
answer = YES |
43 |
Correct |
3 ms |
5224 KB |
answer = YES |
44 |
Correct |
2 ms |
5224 KB |
answer = YES |
45 |
Correct |
3 ms |
5212 KB |
answer = YES |
46 |
Correct |
3 ms |
5212 KB |
answer = YES |
47 |
Correct |
3 ms |
5204 KB |
answer = YES |
48 |
Correct |
2 ms |
5252 KB |
answer = YES |
49 |
Correct |
108 ms |
6240 KB |
answer = YES |
50 |
Correct |
9 ms |
6232 KB |
answer = YES |
51 |
Correct |
98 ms |
6504 KB |
answer = YES |
52 |
Correct |
96 ms |
6496 KB |
answer = NO |
53 |
Correct |
3 ms |
5208 KB |
answer = YES |
54 |
Correct |
9 ms |
5464 KB |
answer = YES |
55 |
Correct |
32 ms |
5736 KB |
answer = YES |
56 |
Correct |
103 ms |
6248 KB |
answer = YES |
57 |
Correct |
22 ms |
5916 KB |
answer = YES |
58 |
Correct |
41 ms |
5976 KB |
answer = YES |
59 |
Correct |
12 ms |
5724 KB |
answer = YES |
60 |
Correct |
51 ms |
5984 KB |
answer = YES |
61 |
Correct |
6 ms |
5464 KB |
answer = YES |
62 |
Correct |
71 ms |
16884 KB |
answer = NO |
63 |
Correct |
75 ms |
16976 KB |
answer = YES |
64 |
Correct |
56 ms |
16712 KB |
answer = NO |
65 |
Correct |
77 ms |
16976 KB |
answer = YES |
66 |
Correct |
7 ms |
5212 KB |
answer = YES |
67 |
Execution timed out |
1076 ms |
20336 KB |
Time limit exceeded |
68 |
Halted |
0 ms |
0 KB |
- |