This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
/**/
//typedef int ll;
typedef long long ll;
typedef unsigned long long ull;
typedef std::string str;
/*typedef __int128 vll;
typedef unsigned __int128 uvll;*/
#define llll std::pair<ll , ll>
#define pb push_back
#define pf push_front
#define halo cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e14 + 7;
const ll ous = 1e5 + 7;
const ll dx[4] = {-1 , 0 , 1 , 0} , dy[4] = {0,1,0,-1};
ll n , m;std::vector<ll> ar(ous) , vis(ous) , svis(ous) , sgn(ous) , val(ous) , kp ;ll cyc = 0;std::vector<long double> ans(ous);
std::vector<llll> adj[ous];
long double oo;
void dfs(ll crt){
vis[crt] = 1;
for(auto j:adj[crt]){
if(vis[j.fi] == 0){
sgn[j.fi] = -sgn[crt];
val[j.fi] = j.sec - val[crt];
kp.pb((-sgn[j.fi])*val[j.fi]);
dfs(j.fi);
}
else if(sgn[crt] == sgn[j.fi]){
cyc = 1;
oo = sgn[j.fi]*(j.sec - val[j.fi] - val[crt])/2.0;
}
}
}
ll ctdfs(ll crt){
svis[crt] = 1;
for(auto j:adj[crt]){
ans[j.fi] = sgn[j.fi] * oo + val[j.fi];
if(ans[j.fi] + ans[crt] != j.sec){
return 0;
}
}
for(auto j:adj[crt]){
if(svis[j.fi] == 0 && ctdfs(j.fi) == 0){
return 0;
}
}
return 1;
}
void solve(){
std::cin >> n >> m;
for(ll i = 0;m>i;i++){
ll x , y , z;std::cin >> x >> y >> z;
adj[x].pb({y , z});
adj[y].pb({x , z});
}
for(ll i = 1;n>=i;i++){
if(vis[i] == 0){
kp.clear();
cyc = 0;
oo = 0;
vis[i] = 1;sgn[i] = 1;val[i] = 0;
kp.pb((-sgn[i])*val[i]);
dfs(i);
if(cyc == 0){
std::sort(all(kp));
oo = kp[kp.size() / 2];
}
ans[i] = sgn[i] * oo + val[i];
//std::cout << ans[i] << " " << oo << " " << cyc << "\n";
if(ctdfs(i) == 0){
std::cout << "NO\n";
return;
}
}
}
std::cout << "YES\n";
for(ll i = 1;n>=i;i++){
std::cout << ans[i] << " ";
}
return;/**/
}
signed main(){
std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
ll t=1;
//std::cin >> t;
ll o = 1;
while(t--){
//cout << "Case " << o++ << ":\n";
solve();
}
return 0;
}/**/
Compilation message (stderr)
Graph.cpp:5:78: warning: "/*" within comment [-Wcomment]
5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
|
Graph.cpp: In function 'int main()':
Graph.cpp:94:8: warning: unused variable 'o' [-Wunused-variable]
94 | ll o = 1;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |