#include<stdio.h>
#include<stdlib.h>
typedef double ld;
int C(const void*a,const void*b){
ld x=*(const ld*)a-*(const ld*)b;
return x<0?-1:(x>0?1:0);
}
#define N 100002
#define M 400001
ld a(ld 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],grp[N],got[N],eo[N<<1];
ld *eh[N<<1];
void push(int i,ld j){
int o=eo[i]++;
if(!o)eh[i]=(ld*)malloc(2*sizeof**eh);
else if(!(o&o-1))eh[i]=(ld*)realloc(eh[i],2*o*sizeof**eh);
eh[i][o]=j;
}
ld xx[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,int cp){
if(vis[u]){
if(a==aa[u]&&b!=bb[u]) exit(puts("NO")*0);
return;
}
grp[u]=cp;
if(a!=0) push(cp,-1.0f*b/a);
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,cp);
}
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);
for(int i=1;i<=n;++i)
if(!vis[i])
dfs(i,1,0,i);
for(int j=1;j<ii;++j){
ld 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(b1==col[j]&&a1==0)continue;
ld x = (col[j]-b1)/a1;
xx[grp[fr[j]]]=x,got[grp[fr[j]]]=1;
}
for(int i=1;i<=n;++i){
if(got[grp[i]])continue;
qsort(eh[grp[i]],eo[grp[i]],sizeof**eh,C);
xx[grp[i]]=eh[grp[i]][(eo[grp[i]])/2];
got[grp[i]]=1;
}
for(int k=1;k<ii;++k)
if(aa[fr[k]]*xx[grp[k]]+bb[fr[k]]+aa[to[k]]*xx[grp[k]]+bb[to[k]] != col[k])exit(puts("NO")*0);
puts("YES");
for(int i=1;i<=n;++i) printf("%.3f ",aa[i]*xx[grp[i]]+bb[i]);
}
Compilation message
Graph.c: In function 'push':
Graph.c:16:18: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
16 | else if(!(o&o-1))eh[i]=(ld*)realloc(eh[i],2*o*sizeof**eh);
| ~^~
Graph.c: In function 'main':
Graph.c:43:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d%d",&n,&m);
| ^~~~~~~~~~~~~~~~~~~
Graph.c:44:31: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | 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);
| ^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
1 ms |
348 KB |
answer = YES |
6 |
Correct |
1 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
348 KB |
answer = YES |
8 |
Correct |
0 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
428 KB |
answer = NO |
10 |
Incorrect |
0 ms |
348 KB |
jury has the better answer: jans = YES, pans = NO |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
1 ms |
348 KB |
answer = YES |
6 |
Correct |
1 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
348 KB |
answer = YES |
8 |
Correct |
0 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
428 KB |
answer = NO |
10 |
Incorrect |
0 ms |
348 KB |
jury has the better answer: jans = YES, pans = NO |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
1 ms |
348 KB |
answer = YES |
6 |
Correct |
1 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
348 KB |
answer = YES |
8 |
Correct |
0 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
428 KB |
answer = NO |
10 |
Incorrect |
0 ms |
348 KB |
jury has the better answer: jans = YES, pans = NO |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
1 ms |
348 KB |
answer = YES |
6 |
Correct |
1 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
348 KB |
answer = YES |
8 |
Correct |
0 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
428 KB |
answer = NO |
10 |
Incorrect |
0 ms |
348 KB |
jury has the better answer: jans = YES, pans = NO |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
1 ms |
348 KB |
answer = YES |
6 |
Correct |
1 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
348 KB |
answer = YES |
8 |
Correct |
0 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
428 KB |
answer = NO |
10 |
Incorrect |
0 ms |
348 KB |
jury has the better answer: jans = YES, pans = NO |
11 |
Halted |
0 ms |
0 KB |
- |