#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;
if(got[grp[fr[j]]]){
if(xx[grp[fr[j]]]!=x)
exit(puts("NO")*0);
}
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;
}
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);
| ^~~~~~~~~~~~~~~~~~~~~~~~
# |
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 |
Correct |
0 ms |
348 KB |
answer = YES |
6 |
Correct |
0 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
344 KB |
answer = YES |
8 |
Correct |
0 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
348 KB |
answer = NO |
10 |
Correct |
0 ms |
348 KB |
answer = YES |
11 |
Correct |
0 ms |
348 KB |
answer = YES |
12 |
Correct |
0 ms |
348 KB |
answer = NO |
13 |
Correct |
0 ms |
348 KB |
answer = YES |
14 |
Correct |
0 ms |
348 KB |
answer = YES |
15 |
Correct |
0 ms |
348 KB |
answer = YES |
16 |
Correct |
0 ms |
348 KB |
answer = YES |
17 |
Correct |
0 ms |
352 KB |
answer = YES |
18 |
Correct |
0 ms |
348 KB |
answer = YES |
19 |
Correct |
0 ms |
348 KB |
answer = YES |
20 |
Correct |
0 ms |
348 KB |
answer = YES |
21 |
Correct |
0 ms |
348 KB |
answer = YES |
22 |
Correct |
0 ms |
348 KB |
answer = NO |
23 |
Correct |
0 ms |
348 KB |
answer = NO |
# |
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 |
Correct |
0 ms |
348 KB |
answer = YES |
6 |
Correct |
0 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
344 KB |
answer = YES |
8 |
Correct |
0 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
348 KB |
answer = NO |
10 |
Correct |
0 ms |
348 KB |
answer = YES |
11 |
Correct |
0 ms |
348 KB |
answer = YES |
12 |
Correct |
0 ms |
348 KB |
answer = NO |
13 |
Correct |
0 ms |
348 KB |
answer = YES |
14 |
Correct |
0 ms |
348 KB |
answer = YES |
15 |
Correct |
0 ms |
348 KB |
answer = YES |
16 |
Correct |
0 ms |
348 KB |
answer = YES |
17 |
Correct |
0 ms |
352 KB |
answer = YES |
18 |
Correct |
0 ms |
348 KB |
answer = YES |
19 |
Correct |
0 ms |
348 KB |
answer = YES |
20 |
Correct |
0 ms |
348 KB |
answer = YES |
21 |
Correct |
0 ms |
348 KB |
answer = YES |
22 |
Correct |
0 ms |
348 KB |
answer = NO |
23 |
Correct |
0 ms |
348 KB |
answer = NO |
24 |
Correct |
0 ms |
348 KB |
answer = YES |
25 |
Correct |
0 ms |
348 KB |
answer = YES |
26 |
Correct |
0 ms |
348 KB |
answer = YES |
27 |
Correct |
0 ms |
432 KB |
answer = YES |
28 |
Correct |
0 ms |
348 KB |
answer = YES |
29 |
Correct |
0 ms |
348 KB |
answer = YES |
30 |
Correct |
0 ms |
348 KB |
answer = NO |
31 |
Correct |
0 ms |
348 KB |
answer = YES |
32 |
Correct |
0 ms |
432 KB |
answer = YES |
33 |
Correct |
0 ms |
348 KB |
answer = YES |
34 |
Correct |
1 ms |
604 KB |
answer = YES |
35 |
Correct |
0 ms |
348 KB |
answer = YES |
36 |
Correct |
1 ms |
348 KB |
answer = YES |
# |
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 |
Correct |
0 ms |
348 KB |
answer = YES |
6 |
Correct |
0 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
344 KB |
answer = YES |
8 |
Correct |
0 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
348 KB |
answer = NO |
10 |
Correct |
0 ms |
348 KB |
answer = YES |
11 |
Correct |
0 ms |
348 KB |
answer = YES |
12 |
Correct |
0 ms |
348 KB |
answer = NO |
13 |
Correct |
0 ms |
348 KB |
answer = YES |
14 |
Correct |
0 ms |
348 KB |
answer = YES |
15 |
Correct |
0 ms |
348 KB |
answer = YES |
16 |
Correct |
0 ms |
348 KB |
answer = YES |
17 |
Correct |
0 ms |
352 KB |
answer = YES |
18 |
Correct |
0 ms |
348 KB |
answer = YES |
19 |
Correct |
0 ms |
348 KB |
answer = YES |
20 |
Correct |
0 ms |
348 KB |
answer = YES |
21 |
Correct |
0 ms |
348 KB |
answer = YES |
22 |
Correct |
0 ms |
348 KB |
answer = NO |
23 |
Correct |
0 ms |
348 KB |
answer = NO |
24 |
Correct |
0 ms |
348 KB |
answer = YES |
25 |
Correct |
0 ms |
348 KB |
answer = YES |
26 |
Correct |
0 ms |
348 KB |
answer = YES |
27 |
Correct |
0 ms |
432 KB |
answer = YES |
28 |
Correct |
0 ms |
348 KB |
answer = YES |
29 |
Correct |
0 ms |
348 KB |
answer = YES |
30 |
Correct |
0 ms |
348 KB |
answer = NO |
31 |
Correct |
0 ms |
348 KB |
answer = YES |
32 |
Correct |
0 ms |
432 KB |
answer = YES |
33 |
Correct |
0 ms |
348 KB |
answer = YES |
34 |
Correct |
1 ms |
604 KB |
answer = YES |
35 |
Correct |
0 ms |
348 KB |
answer = YES |
36 |
Correct |
1 ms |
348 KB |
answer = YES |
37 |
Correct |
1 ms |
344 KB |
answer = YES |
38 |
Correct |
1 ms |
344 KB |
answer = YES |
39 |
Correct |
0 ms |
348 KB |
answer = YES |
40 |
Correct |
0 ms |
348 KB |
answer = YES |
41 |
Correct |
1 ms |
348 KB |
answer = NO |
42 |
Correct |
1 ms |
440 KB |
answer = YES |
43 |
Correct |
1 ms |
348 KB |
answer = YES |
44 |
Correct |
1 ms |
348 KB |
answer = YES |
45 |
Correct |
0 ms |
348 KB |
answer = YES |
46 |
Correct |
0 ms |
348 KB |
answer = YES |
47 |
Correct |
1 ms |
348 KB |
answer = YES |
48 |
Correct |
1 ms |
348 KB |
answer = YES |
# |
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 |
Correct |
0 ms |
348 KB |
answer = YES |
6 |
Correct |
0 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
344 KB |
answer = YES |
8 |
Correct |
0 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
348 KB |
answer = NO |
10 |
Correct |
0 ms |
348 KB |
answer = YES |
11 |
Correct |
0 ms |
348 KB |
answer = YES |
12 |
Correct |
0 ms |
348 KB |
answer = NO |
13 |
Correct |
0 ms |
348 KB |
answer = YES |
14 |
Correct |
0 ms |
348 KB |
answer = YES |
15 |
Correct |
0 ms |
348 KB |
answer = YES |
16 |
Correct |
0 ms |
348 KB |
answer = YES |
17 |
Correct |
0 ms |
352 KB |
answer = YES |
18 |
Correct |
0 ms |
348 KB |
answer = YES |
19 |
Correct |
0 ms |
348 KB |
answer = YES |
20 |
Correct |
0 ms |
348 KB |
answer = YES |
21 |
Correct |
0 ms |
348 KB |
answer = YES |
22 |
Correct |
0 ms |
348 KB |
answer = NO |
23 |
Correct |
0 ms |
348 KB |
answer = NO |
24 |
Correct |
0 ms |
348 KB |
answer = YES |
25 |
Correct |
0 ms |
348 KB |
answer = YES |
26 |
Correct |
0 ms |
348 KB |
answer = YES |
27 |
Correct |
0 ms |
432 KB |
answer = YES |
28 |
Correct |
0 ms |
348 KB |
answer = YES |
29 |
Correct |
0 ms |
348 KB |
answer = YES |
30 |
Correct |
0 ms |
348 KB |
answer = NO |
31 |
Correct |
0 ms |
348 KB |
answer = YES |
32 |
Correct |
0 ms |
432 KB |
answer = YES |
33 |
Correct |
0 ms |
348 KB |
answer = YES |
34 |
Correct |
1 ms |
604 KB |
answer = YES |
35 |
Correct |
0 ms |
348 KB |
answer = YES |
36 |
Correct |
1 ms |
348 KB |
answer = YES |
37 |
Correct |
1 ms |
344 KB |
answer = YES |
38 |
Correct |
1 ms |
344 KB |
answer = YES |
39 |
Correct |
0 ms |
348 KB |
answer = YES |
40 |
Correct |
0 ms |
348 KB |
answer = YES |
41 |
Correct |
1 ms |
348 KB |
answer = NO |
42 |
Correct |
1 ms |
440 KB |
answer = YES |
43 |
Correct |
1 ms |
348 KB |
answer = YES |
44 |
Correct |
1 ms |
348 KB |
answer = YES |
45 |
Correct |
0 ms |
348 KB |
answer = YES |
46 |
Correct |
0 ms |
348 KB |
answer = YES |
47 |
Correct |
1 ms |
348 KB |
answer = YES |
48 |
Correct |
1 ms |
348 KB |
answer = YES |
49 |
Correct |
4 ms |
1116 KB |
answer = YES |
50 |
Correct |
4 ms |
1372 KB |
answer = YES |
51 |
Correct |
4 ms |
1628 KB |
answer = YES |
52 |
Correct |
2 ms |
1372 KB |
answer = NO |
53 |
Correct |
1 ms |
356 KB |
answer = YES |
54 |
Correct |
1 ms |
604 KB |
answer = YES |
55 |
Correct |
2 ms |
860 KB |
answer = YES |
56 |
Correct |
4 ms |
1116 KB |
answer = YES |
57 |
Correct |
4 ms |
1372 KB |
answer = YES |
58 |
Correct |
3 ms |
1116 KB |
answer = YES |
59 |
Correct |
3 ms |
1116 KB |
answer = YES |
60 |
Correct |
5 ms |
1364 KB |
answer = YES |
61 |
Correct |
2 ms |
860 KB |
answer = YES |
62 |
Correct |
29 ms |
9040 KB |
answer = NO |
63 |
Correct |
46 ms |
9672 KB |
answer = YES |
64 |
Correct |
31 ms |
9280 KB |
answer = NO |
65 |
Correct |
43 ms |
9688 KB |
answer = YES |
66 |
Correct |
1 ms |
604 KB |
answer = YES |
# |
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 |
Correct |
0 ms |
348 KB |
answer = YES |
6 |
Correct |
0 ms |
348 KB |
answer = YES |
7 |
Correct |
0 ms |
344 KB |
answer = YES |
8 |
Correct |
0 ms |
348 KB |
answer = YES |
9 |
Correct |
0 ms |
348 KB |
answer = NO |
10 |
Correct |
0 ms |
348 KB |
answer = YES |
11 |
Correct |
0 ms |
348 KB |
answer = YES |
12 |
Correct |
0 ms |
348 KB |
answer = NO |
13 |
Correct |
0 ms |
348 KB |
answer = YES |
14 |
Correct |
0 ms |
348 KB |
answer = YES |
15 |
Correct |
0 ms |
348 KB |
answer = YES |
16 |
Correct |
0 ms |
348 KB |
answer = YES |
17 |
Correct |
0 ms |
352 KB |
answer = YES |
18 |
Correct |
0 ms |
348 KB |
answer = YES |
19 |
Correct |
0 ms |
348 KB |
answer = YES |
20 |
Correct |
0 ms |
348 KB |
answer = YES |
21 |
Correct |
0 ms |
348 KB |
answer = YES |
22 |
Correct |
0 ms |
348 KB |
answer = NO |
23 |
Correct |
0 ms |
348 KB |
answer = NO |
24 |
Correct |
0 ms |
348 KB |
answer = YES |
25 |
Correct |
0 ms |
348 KB |
answer = YES |
26 |
Correct |
0 ms |
348 KB |
answer = YES |
27 |
Correct |
0 ms |
432 KB |
answer = YES |
28 |
Correct |
0 ms |
348 KB |
answer = YES |
29 |
Correct |
0 ms |
348 KB |
answer = YES |
30 |
Correct |
0 ms |
348 KB |
answer = NO |
31 |
Correct |
0 ms |
348 KB |
answer = YES |
32 |
Correct |
0 ms |
432 KB |
answer = YES |
33 |
Correct |
0 ms |
348 KB |
answer = YES |
34 |
Correct |
1 ms |
604 KB |
answer = YES |
35 |
Correct |
0 ms |
348 KB |
answer = YES |
36 |
Correct |
1 ms |
348 KB |
answer = YES |
37 |
Correct |
1 ms |
344 KB |
answer = YES |
38 |
Correct |
1 ms |
344 KB |
answer = YES |
39 |
Correct |
0 ms |
348 KB |
answer = YES |
40 |
Correct |
0 ms |
348 KB |
answer = YES |
41 |
Correct |
1 ms |
348 KB |
answer = NO |
42 |
Correct |
1 ms |
440 KB |
answer = YES |
43 |
Correct |
1 ms |
348 KB |
answer = YES |
44 |
Correct |
1 ms |
348 KB |
answer = YES |
45 |
Correct |
0 ms |
348 KB |
answer = YES |
46 |
Correct |
0 ms |
348 KB |
answer = YES |
47 |
Correct |
1 ms |
348 KB |
answer = YES |
48 |
Correct |
1 ms |
348 KB |
answer = YES |
49 |
Correct |
4 ms |
1116 KB |
answer = YES |
50 |
Correct |
4 ms |
1372 KB |
answer = YES |
51 |
Correct |
4 ms |
1628 KB |
answer = YES |
52 |
Correct |
2 ms |
1372 KB |
answer = NO |
53 |
Correct |
1 ms |
356 KB |
answer = YES |
54 |
Correct |
1 ms |
604 KB |
answer = YES |
55 |
Correct |
2 ms |
860 KB |
answer = YES |
56 |
Correct |
4 ms |
1116 KB |
answer = YES |
57 |
Correct |
4 ms |
1372 KB |
answer = YES |
58 |
Correct |
3 ms |
1116 KB |
answer = YES |
59 |
Correct |
3 ms |
1116 KB |
answer = YES |
60 |
Correct |
5 ms |
1364 KB |
answer = YES |
61 |
Correct |
2 ms |
860 KB |
answer = YES |
62 |
Correct |
29 ms |
9040 KB |
answer = NO |
63 |
Correct |
46 ms |
9672 KB |
answer = YES |
64 |
Correct |
31 ms |
9280 KB |
answer = NO |
65 |
Correct |
43 ms |
9688 KB |
answer = YES |
66 |
Correct |
1 ms |
604 KB |
answer = YES |
67 |
Correct |
54 ms |
14676 KB |
answer = YES |
68 |
Correct |
38 ms |
14632 KB |
answer = YES |
69 |
Correct |
33 ms |
14420 KB |
answer = YES |
70 |
Correct |
48 ms |
18048 KB |
answer = YES |
71 |
Correct |
36 ms |
14584 KB |
answer = YES |
72 |
Correct |
46 ms |
8540 KB |
answer = YES |
73 |
Correct |
38 ms |
8300 KB |
answer = YES |
74 |
Correct |
29 ms |
8784 KB |
answer = YES |
75 |
Correct |
15 ms |
8416 KB |
answer = NO |
76 |
Correct |
5 ms |
1372 KB |
answer = YES |
77 |
Correct |
11 ms |
2492 KB |
answer = YES |
78 |
Correct |
25 ms |
4028 KB |
answer = YES |
79 |
Correct |
48 ms |
7268 KB |
answer = YES |
80 |
Correct |
42 ms |
9012 KB |
answer = YES |
81 |
Correct |
22 ms |
10956 KB |
answer = NO |
82 |
Correct |
45 ms |
11676 KB |
answer = YES |
83 |
Correct |
58 ms |
14836 KB |
answer = YES |
84 |
Correct |
56 ms |
14608 KB |
answer = YES |
85 |
Correct |
52 ms |
14764 KB |
answer = YES |
86 |
Correct |
43 ms |
14580 KB |
answer = YES |
87 |
Correct |
33 ms |
9064 KB |
answer = NO |
88 |
Correct |
50 ms |
11040 KB |
answer = YES |
89 |
Correct |
39 ms |
10784 KB |
answer = YES |
90 |
Correct |
40 ms |
10760 KB |
answer = YES |
91 |
Correct |
46 ms |
10824 KB |
answer = YES |
92 |
Correct |
25 ms |
4436 KB |
answer = YES |
93 |
Correct |
19 ms |
4444 KB |
answer = YES |
94 |
Correct |
32 ms |
13956 KB |
answer = NO |
95 |
Correct |
30 ms |
9712 KB |
answer = NO |
96 |
Correct |
84 ms |
18760 KB |
answer = YES |
97 |
Correct |
27 ms |
13980 KB |
answer = NO |