#include<stdio.h>
#include<stdlib.h>
#define N 100001
#define M 400001
double a(double x){return x<0?-x:x;}
int n,m,head[N],fr[M],to[M],nxt[M],col[M],ii,vis[N],aa[N],bb[N];
void link(int u,int v,int c){
int i=++ii;
to[i]=v;
fr[i]=u;
col[i]=c;
nxt[i]=head[u];
head[u]=i;
}
void dfs(int u,int a,int b){
if(vis[u]){
if(a==aa[u]&&b!=bb[u])
exit(puts("NO")*0);
return;
}
vis[u]=1,aa[u]=a,bb[u]=b;
for(int j=head[u];j;j=nxt[j])
dfs(to[j],-a,col[j]-b);
}
int main(){
scanf("%d%d",&n,&m);
for(int u,v,c,i=0;i<m;++i)scanf("%d%d%d",&u,&v,&c),link(u,v,c),link(v,u,c);
dfs(1,1,0);
for(int j=1;j<ii;++j){
double a1=aa[fr[j]]+aa[to[j]],b1=bb[fr[j]]+bb[to[j]];
if(a1==0&&b1!=col[j])exit(puts("NO")*0);
if(a1==0)continue;
if(b1==col[j]&&a1==0)continue;
int ok=1;
double x = (col[j]-b1)/a1;
for(int k=1;k<ii&&ok;++k)
if(aa[fr[k]]*x+bb[fr[k]]+aa[to[k]]*x+bb[to[k]] != col[k])ok=0;
if(ok){
puts("YES");
for(int i=1;i<=n;++i) printf("%.3f ",aa[i]*x+bb[i]);
return 0;
}
}
double min=1e18,argmin=424242;
for(double f=-10000;f<=10000;f+=0.5){
double sum=0;
for(int i=1;i<=n;++i)sum+=a(aa[i]*f+bb[i]);
if(min>sum) min=sum,argmin=f;
}
puts("YES");
for(int i=1;i<=n;++i) printf("%.3f ",aa[i]*argmin+bb[i]);
}
Compilation message
Graph.c: In function 'main':
Graph.c:29:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d%d",&n,&m);
| ^~~~~~~~~~~~~~~~~~~
Graph.c:30:31: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | for(int u,v,c,i=0;i<m;++i)scanf("%d%d%d",&u,&v,&c),link(u,v,c),link(v,u,c);
| ^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
answer = YES |
2 |
Correct |
0 ms |
348 KB |
answer = YES |
3 |
Correct |
0 ms |
348 KB |
answer = YES |
4 |
Correct |
0 ms |
348 KB |
answer = NO |
5 |
Incorrect |
0 ms |
348 KB |
jury has the better answer: jans = YES, pans = NO |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
answer = YES |
2 |
Correct |
0 ms |
348 KB |
answer = YES |
3 |
Correct |
0 ms |
348 KB |
answer = YES |
4 |
Correct |
0 ms |
348 KB |
answer = NO |
5 |
Incorrect |
0 ms |
348 KB |
jury has the better answer: jans = YES, pans = NO |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
answer = YES |
2 |
Correct |
0 ms |
348 KB |
answer = YES |
3 |
Correct |
0 ms |
348 KB |
answer = YES |
4 |
Correct |
0 ms |
348 KB |
answer = NO |
5 |
Incorrect |
0 ms |
348 KB |
jury has the better answer: jans = YES, pans = NO |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
answer = YES |
2 |
Correct |
0 ms |
348 KB |
answer = YES |
3 |
Correct |
0 ms |
348 KB |
answer = YES |
4 |
Correct |
0 ms |
348 KB |
answer = NO |
5 |
Incorrect |
0 ms |
348 KB |
jury has the better answer: jans = YES, pans = NO |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
answer = YES |
2 |
Correct |
0 ms |
348 KB |
answer = YES |
3 |
Correct |
0 ms |
348 KB |
answer = YES |
4 |
Correct |
0 ms |
348 KB |
answer = NO |
5 |
Incorrect |
0 ms |
348 KB |
jury has the better answer: jans = YES, pans = NO |
6 |
Halted |
0 ms |
0 KB |
- |