#include "bits/stdc++.h"
//#pragma GCC optimize("O3")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pairll;
typedef long double ld;
#define fr first
#define sc second
#define pb push_back
#define INF 100000000007
#define endl '\n'
#define MOD 998244353
#define A 31
#define N 100007
#define eps 0.00000001
ll n,m,a[N],b[N],f[N];
ld res[N];
vector<pairll>v[N];
vector<ll>num;
ld S(ll x,ll a1,ll b1,ll y){
if(f[x]==1 && a[x]!=a1){
return ld(b1-b[x])/ld(a[x]-a1);
}else if(f[x]==1 && b[x]!=b1)return -INF;
else if(f[x]==1)return INF;
num.pb(x);
f[x]=1;
a[x]=a1;
b[x]=b1;
for(int i=0;i<v[x].size();i++){
if(v[x][i].fr!=y){
ld r=S(v[x][i].fr,0-a1,v[x][i].sc-b1,x);
if(r!=INF)return r;
}
}
return INF;
}
ll D(ll x,ll y,ld a1){
f[x]=2;
res[x]=a1;
for(auto it:v[x]){
if(it.fr!=y){
if(f[it.fr]==2){
if(abs(a1+res[it.fr]-ld(it.sc))>eps)return 1;
}else{
ll r=D(it.fr,x,ld(it.sc)-a1);
if(r==1)return 1;
}
}
}
return 0;
}
int main(){
cin>>n>>m;
for(int i=1;i<=m;i++){
ll x,y,z;
cin>>x>>y>>z;
v[x].pb({y,z});
v[y].pb({x,z});
}
for(int i=1;i<=n;i++){
if(f[i]==0){
num.clear();
ld x=S(i,1,0,0);
if(x==-INF){
cout<<"NO"<<endl;
return 0;
}else if(x==INF){
ld l=-100;
ld r=100;
ld r1=0;
ld r2=0;
while(r-l>eps){
ld m1=(l+(r-l)/3.0);
ld m2=(r-(r-l)/3.0);
r1=0;
r2=0;
for(auto j:num){
r1+=abs(m1*ld(a[j])+ld(b[j]));
r2+=abs(m2*ld(a[j])+ld(b[j]));
}
if(r1<r2)r=m2;
else l=m1;
}
for(auto j:num){
res[j]=l*ld(a[j])+ld(b[j]);
}
}else{
ll r=D(i,0,x);
if(r==1){
cout<<"NO"<<endl;
return 0;
}
}
}
}
cout<<"YES"<<endl;
for(int i=1;i<=n;i++){
cout<<fixed<<setprecision(10)<<res[i]<<" ";
}
cout<<endl;
return 0;
}
Compilation message
Graph.cpp: In function 'ld S(ll, ll, ll, ll)':
Graph.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0;i<v[x].size();i++){
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2644 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2664 KB |
answer = YES |
14 |
Correct |
2 ms |
2660 KB |
answer = YES |
15 |
Correct |
2 ms |
2660 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
2 ms |
2644 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2660 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2656 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2644 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2664 KB |
answer = YES |
14 |
Correct |
2 ms |
2660 KB |
answer = YES |
15 |
Correct |
2 ms |
2660 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
2 ms |
2644 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2660 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2656 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2660 KB |
answer = YES |
25 |
Correct |
2 ms |
2656 KB |
answer = YES |
26 |
Correct |
2 ms |
2644 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
3 ms |
2664 KB |
answer = YES |
30 |
Correct |
3 ms |
2644 KB |
answer = NO |
31 |
Correct |
2 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2656 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
2 ms |
2656 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
2 ms |
2644 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2644 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2664 KB |
answer = YES |
14 |
Correct |
2 ms |
2660 KB |
answer = YES |
15 |
Correct |
2 ms |
2660 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
2 ms |
2644 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2660 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2656 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2660 KB |
answer = YES |
25 |
Correct |
2 ms |
2656 KB |
answer = YES |
26 |
Correct |
2 ms |
2644 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
3 ms |
2664 KB |
answer = YES |
30 |
Correct |
3 ms |
2644 KB |
answer = NO |
31 |
Correct |
2 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2656 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
2 ms |
2656 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 |
2644 KB |
answer = YES |
39 |
Correct |
3 ms |
2644 KB |
answer = YES |
40 |
Correct |
3 ms |
2772 KB |
answer = YES |
41 |
Correct |
3 ms |
2664 KB |
answer = NO |
42 |
Correct |
5 ms |
2868 KB |
answer = YES |
43 |
Incorrect |
3 ms |
2772 KB |
participant answer is larger than the answer of jury |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2644 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2664 KB |
answer = YES |
14 |
Correct |
2 ms |
2660 KB |
answer = YES |
15 |
Correct |
2 ms |
2660 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
2 ms |
2644 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2660 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2656 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2660 KB |
answer = YES |
25 |
Correct |
2 ms |
2656 KB |
answer = YES |
26 |
Correct |
2 ms |
2644 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
3 ms |
2664 KB |
answer = YES |
30 |
Correct |
3 ms |
2644 KB |
answer = NO |
31 |
Correct |
2 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2656 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
2 ms |
2656 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 |
2644 KB |
answer = YES |
39 |
Correct |
3 ms |
2644 KB |
answer = YES |
40 |
Correct |
3 ms |
2772 KB |
answer = YES |
41 |
Correct |
3 ms |
2664 KB |
answer = NO |
42 |
Correct |
5 ms |
2868 KB |
answer = YES |
43 |
Incorrect |
3 ms |
2772 KB |
participant answer is larger than the answer of jury |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2644 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2664 KB |
answer = YES |
14 |
Correct |
2 ms |
2660 KB |
answer = YES |
15 |
Correct |
2 ms |
2660 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2644 KB |
answer = YES |
18 |
Correct |
2 ms |
2644 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2660 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2656 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2660 KB |
answer = YES |
25 |
Correct |
2 ms |
2656 KB |
answer = YES |
26 |
Correct |
2 ms |
2644 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
3 ms |
2664 KB |
answer = YES |
30 |
Correct |
3 ms |
2644 KB |
answer = NO |
31 |
Correct |
2 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2656 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
2 ms |
2656 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 |
2644 KB |
answer = YES |
39 |
Correct |
3 ms |
2644 KB |
answer = YES |
40 |
Correct |
3 ms |
2772 KB |
answer = YES |
41 |
Correct |
3 ms |
2664 KB |
answer = NO |
42 |
Correct |
5 ms |
2868 KB |
answer = YES |
43 |
Incorrect |
3 ms |
2772 KB |
participant answer is larger than the answer of jury |
44 |
Halted |
0 ms |
0 KB |
- |