#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);
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[fix.ff] = fix.ss;
dfs2(fix.ff);
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] = 0;
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 |
4956 KB |
answer = YES |
4 |
Correct |
2 ms |
5180 KB |
answer = NO |
5 |
Correct |
2 ms |
5208 KB |
answer = YES |
6 |
Incorrect |
2 ms |
4956 KB |
participant answer is larger than the answer of jury |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
answer = YES |
2 |
Correct |
2 ms |
4956 KB |
answer = YES |
3 |
Correct |
2 ms |
4956 KB |
answer = YES |
4 |
Correct |
2 ms |
5180 KB |
answer = NO |
5 |
Correct |
2 ms |
5208 KB |
answer = YES |
6 |
Incorrect |
2 ms |
4956 KB |
participant answer is larger than the answer of jury |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
answer = YES |
2 |
Correct |
2 ms |
4956 KB |
answer = YES |
3 |
Correct |
2 ms |
4956 KB |
answer = YES |
4 |
Correct |
2 ms |
5180 KB |
answer = NO |
5 |
Correct |
2 ms |
5208 KB |
answer = YES |
6 |
Incorrect |
2 ms |
4956 KB |
participant answer is larger than the answer of jury |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
answer = YES |
2 |
Correct |
2 ms |
4956 KB |
answer = YES |
3 |
Correct |
2 ms |
4956 KB |
answer = YES |
4 |
Correct |
2 ms |
5180 KB |
answer = NO |
5 |
Correct |
2 ms |
5208 KB |
answer = YES |
6 |
Incorrect |
2 ms |
4956 KB |
participant answer is larger than the answer of jury |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
answer = YES |
2 |
Correct |
2 ms |
4956 KB |
answer = YES |
3 |
Correct |
2 ms |
4956 KB |
answer = YES |
4 |
Correct |
2 ms |
5180 KB |
answer = NO |
5 |
Correct |
2 ms |
5208 KB |
answer = YES |
6 |
Incorrect |
2 ms |
4956 KB |
participant answer is larger than the answer of jury |
7 |
Halted |
0 ms |
0 KB |
- |