#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(int x = -2*n; x <= 2*n; ++x){
// 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 |
4956 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 |
4940 KB |
answer = YES |
6 |
Correct |
2 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 |
4956 KB |
answer = NO |
10 |
Correct |
2 ms |
4956 KB |
answer = YES |
11 |
Correct |
2 ms |
4956 KB |
answer = YES |
12 |
Correct |
2 ms |
4956 KB |
answer = NO |
13 |
Correct |
2 ms |
4956 KB |
answer = YES |
14 |
Correct |
2 ms |
4956 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 |
5040 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 |
2 ms |
4952 KB |
answer = NO |
23 |
Correct |
2 ms |
4956 KB |
answer = NO |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 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 |
4940 KB |
answer = YES |
6 |
Correct |
2 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 |
4956 KB |
answer = NO |
10 |
Correct |
2 ms |
4956 KB |
answer = YES |
11 |
Correct |
2 ms |
4956 KB |
answer = YES |
12 |
Correct |
2 ms |
4956 KB |
answer = NO |
13 |
Correct |
2 ms |
4956 KB |
answer = YES |
14 |
Correct |
2 ms |
4956 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 |
5040 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 |
2 ms |
4952 KB |
answer = NO |
23 |
Correct |
2 ms |
4956 KB |
answer = NO |
24 |
Correct |
2 ms |
4952 KB |
answer = YES |
25 |
Correct |
2 ms |
4956 KB |
answer = YES |
26 |
Correct |
2 ms |
5188 KB |
answer = YES |
27 |
Correct |
2 ms |
4956 KB |
answer = YES |
28 |
Correct |
2 ms |
4956 KB |
answer = YES |
29 |
Correct |
2 ms |
4952 KB |
answer = YES |
30 |
Correct |
2 ms |
4956 KB |
answer = NO |
31 |
Correct |
2 ms |
4956 KB |
answer = YES |
32 |
Correct |
2 ms |
4956 KB |
answer = YES |
33 |
Correct |
2 ms |
4956 KB |
answer = YES |
34 |
Correct |
2 ms |
4956 KB |
answer = YES |
35 |
Correct |
2 ms |
4956 KB |
answer = YES |
36 |
Correct |
2 ms |
4956 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 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 |
4940 KB |
answer = YES |
6 |
Correct |
2 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 |
4956 KB |
answer = NO |
10 |
Correct |
2 ms |
4956 KB |
answer = YES |
11 |
Correct |
2 ms |
4956 KB |
answer = YES |
12 |
Correct |
2 ms |
4956 KB |
answer = NO |
13 |
Correct |
2 ms |
4956 KB |
answer = YES |
14 |
Correct |
2 ms |
4956 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 |
5040 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 |
2 ms |
4952 KB |
answer = NO |
23 |
Correct |
2 ms |
4956 KB |
answer = NO |
24 |
Correct |
2 ms |
4952 KB |
answer = YES |
25 |
Correct |
2 ms |
4956 KB |
answer = YES |
26 |
Correct |
2 ms |
5188 KB |
answer = YES |
27 |
Correct |
2 ms |
4956 KB |
answer = YES |
28 |
Correct |
2 ms |
4956 KB |
answer = YES |
29 |
Correct |
2 ms |
4952 KB |
answer = YES |
30 |
Correct |
2 ms |
4956 KB |
answer = NO |
31 |
Correct |
2 ms |
4956 KB |
answer = YES |
32 |
Correct |
2 ms |
4956 KB |
answer = YES |
33 |
Correct |
2 ms |
4956 KB |
answer = YES |
34 |
Correct |
2 ms |
4956 KB |
answer = YES |
35 |
Correct |
2 ms |
4956 KB |
answer = YES |
36 |
Correct |
2 ms |
4956 KB |
answer = YES |
37 |
Correct |
2 ms |
5180 KB |
answer = YES |
38 |
Correct |
2 ms |
4956 KB |
answer = YES |
39 |
Correct |
3 ms |
5212 KB |
answer = YES |
40 |
Correct |
2 ms |
5212 KB |
answer = YES |
41 |
Correct |
5 ms |
5212 KB |
answer = NO |
42 |
Correct |
5 ms |
5208 KB |
answer = YES |
43 |
Correct |
6 ms |
5212 KB |
answer = YES |
44 |
Correct |
6 ms |
5212 KB |
answer = YES |
45 |
Correct |
3 ms |
5212 KB |
answer = YES |
46 |
Correct |
3 ms |
5212 KB |
answer = YES |
47 |
Correct |
2 ms |
5212 KB |
answer = YES |
48 |
Correct |
3 ms |
5208 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 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 |
4940 KB |
answer = YES |
6 |
Correct |
2 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 |
4956 KB |
answer = NO |
10 |
Correct |
2 ms |
4956 KB |
answer = YES |
11 |
Correct |
2 ms |
4956 KB |
answer = YES |
12 |
Correct |
2 ms |
4956 KB |
answer = NO |
13 |
Correct |
2 ms |
4956 KB |
answer = YES |
14 |
Correct |
2 ms |
4956 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 |
5040 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 |
2 ms |
4952 KB |
answer = NO |
23 |
Correct |
2 ms |
4956 KB |
answer = NO |
24 |
Correct |
2 ms |
4952 KB |
answer = YES |
25 |
Correct |
2 ms |
4956 KB |
answer = YES |
26 |
Correct |
2 ms |
5188 KB |
answer = YES |
27 |
Correct |
2 ms |
4956 KB |
answer = YES |
28 |
Correct |
2 ms |
4956 KB |
answer = YES |
29 |
Correct |
2 ms |
4952 KB |
answer = YES |
30 |
Correct |
2 ms |
4956 KB |
answer = NO |
31 |
Correct |
2 ms |
4956 KB |
answer = YES |
32 |
Correct |
2 ms |
4956 KB |
answer = YES |
33 |
Correct |
2 ms |
4956 KB |
answer = YES |
34 |
Correct |
2 ms |
4956 KB |
answer = YES |
35 |
Correct |
2 ms |
4956 KB |
answer = YES |
36 |
Correct |
2 ms |
4956 KB |
answer = YES |
37 |
Correct |
2 ms |
5180 KB |
answer = YES |
38 |
Correct |
2 ms |
4956 KB |
answer = YES |
39 |
Correct |
3 ms |
5212 KB |
answer = YES |
40 |
Correct |
2 ms |
5212 KB |
answer = YES |
41 |
Correct |
5 ms |
5212 KB |
answer = NO |
42 |
Correct |
5 ms |
5208 KB |
answer = YES |
43 |
Correct |
6 ms |
5212 KB |
answer = YES |
44 |
Correct |
6 ms |
5212 KB |
answer = YES |
45 |
Correct |
3 ms |
5212 KB |
answer = YES |
46 |
Correct |
3 ms |
5212 KB |
answer = YES |
47 |
Correct |
2 ms |
5212 KB |
answer = YES |
48 |
Correct |
3 ms |
5208 KB |
answer = YES |
49 |
Correct |
376 ms |
6232 KB |
answer = YES |
50 |
Correct |
9 ms |
6236 KB |
answer = YES |
51 |
Correct |
379 ms |
6492 KB |
answer = YES |
52 |
Correct |
376 ms |
6488 KB |
answer = NO |
53 |
Correct |
6 ms |
5208 KB |
answer = YES |
54 |
Correct |
24 ms |
5468 KB |
answer = YES |
55 |
Correct |
98 ms |
5728 KB |
answer = YES |
56 |
Correct |
372 ms |
6236 KB |
answer = YES |
57 |
Correct |
405 ms |
5820 KB |
answer = YES |
58 |
Correct |
306 ms |
6048 KB |
answer = YES |
59 |
Correct |
8 ms |
5976 KB |
answer = YES |
60 |
Correct |
377 ms |
6028 KB |
answer = YES |
61 |
Correct |
5 ms |
5464 KB |
answer = YES |
62 |
Correct |
44 ms |
16804 KB |
answer = NO |
63 |
Correct |
49 ms |
16988 KB |
answer = YES |
64 |
Correct |
44 ms |
16928 KB |
answer = NO |
65 |
Correct |
47 ms |
16832 KB |
answer = YES |
66 |
Correct |
19 ms |
5208 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 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 |
4940 KB |
answer = YES |
6 |
Correct |
2 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 |
4956 KB |
answer = NO |
10 |
Correct |
2 ms |
4956 KB |
answer = YES |
11 |
Correct |
2 ms |
4956 KB |
answer = YES |
12 |
Correct |
2 ms |
4956 KB |
answer = NO |
13 |
Correct |
2 ms |
4956 KB |
answer = YES |
14 |
Correct |
2 ms |
4956 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 |
5040 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 |
2 ms |
4952 KB |
answer = NO |
23 |
Correct |
2 ms |
4956 KB |
answer = NO |
24 |
Correct |
2 ms |
4952 KB |
answer = YES |
25 |
Correct |
2 ms |
4956 KB |
answer = YES |
26 |
Correct |
2 ms |
5188 KB |
answer = YES |
27 |
Correct |
2 ms |
4956 KB |
answer = YES |
28 |
Correct |
2 ms |
4956 KB |
answer = YES |
29 |
Correct |
2 ms |
4952 KB |
answer = YES |
30 |
Correct |
2 ms |
4956 KB |
answer = NO |
31 |
Correct |
2 ms |
4956 KB |
answer = YES |
32 |
Correct |
2 ms |
4956 KB |
answer = YES |
33 |
Correct |
2 ms |
4956 KB |
answer = YES |
34 |
Correct |
2 ms |
4956 KB |
answer = YES |
35 |
Correct |
2 ms |
4956 KB |
answer = YES |
36 |
Correct |
2 ms |
4956 KB |
answer = YES |
37 |
Correct |
2 ms |
5180 KB |
answer = YES |
38 |
Correct |
2 ms |
4956 KB |
answer = YES |
39 |
Correct |
3 ms |
5212 KB |
answer = YES |
40 |
Correct |
2 ms |
5212 KB |
answer = YES |
41 |
Correct |
5 ms |
5212 KB |
answer = NO |
42 |
Correct |
5 ms |
5208 KB |
answer = YES |
43 |
Correct |
6 ms |
5212 KB |
answer = YES |
44 |
Correct |
6 ms |
5212 KB |
answer = YES |
45 |
Correct |
3 ms |
5212 KB |
answer = YES |
46 |
Correct |
3 ms |
5212 KB |
answer = YES |
47 |
Correct |
2 ms |
5212 KB |
answer = YES |
48 |
Correct |
3 ms |
5208 KB |
answer = YES |
49 |
Correct |
376 ms |
6232 KB |
answer = YES |
50 |
Correct |
9 ms |
6236 KB |
answer = YES |
51 |
Correct |
379 ms |
6492 KB |
answer = YES |
52 |
Correct |
376 ms |
6488 KB |
answer = NO |
53 |
Correct |
6 ms |
5208 KB |
answer = YES |
54 |
Correct |
24 ms |
5468 KB |
answer = YES |
55 |
Correct |
98 ms |
5728 KB |
answer = YES |
56 |
Correct |
372 ms |
6236 KB |
answer = YES |
57 |
Correct |
405 ms |
5820 KB |
answer = YES |
58 |
Correct |
306 ms |
6048 KB |
answer = YES |
59 |
Correct |
8 ms |
5976 KB |
answer = YES |
60 |
Correct |
377 ms |
6028 KB |
answer = YES |
61 |
Correct |
5 ms |
5464 KB |
answer = YES |
62 |
Correct |
44 ms |
16804 KB |
answer = NO |
63 |
Correct |
49 ms |
16988 KB |
answer = YES |
64 |
Correct |
44 ms |
16928 KB |
answer = NO |
65 |
Correct |
47 ms |
16832 KB |
answer = YES |
66 |
Correct |
19 ms |
5208 KB |
answer = YES |
67 |
Execution timed out |
1027 ms |
20280 KB |
Time limit exceeded |
68 |
Halted |
0 ms |
0 KB |
- |