#include<bits/stdc++.h>
using namespace std;
using db = double;
const int N=1e5+5;
const db INVPHI=(sqrt(db(5))-1)/2;
int n,m;
vector<int> adj[N];
bool vis[N];
int a[N],b[N],ans[N];
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> m;
vector<vector<pair<int,int>>> adj(n);
for(int i=0;i<m;i++){
int u,v,w;
cin >> u >> v >> w;
u--,v--;
adj[u].emplace_back(v,w);
adj[v].emplace_back(u,w);
}
vector<int> comp;
pair<int,int> val;
bool found=false;
function<void(int)> dfs=[&](int u){
comp.emplace_back(u);
vis[u]=true;
for(auto [v,w]:adj[u]){
if(!vis[v]){
a[v]=-a[u];
b[v]=w-b[u];
dfs(v);
}else{
if(a[u]+a[v]==0){
if(b[u]+b[v]!=w){
cout << "NO",exit(0);
}
}else{
int num=w-b[u]-b[v];
int den=a[u]+a[v];
if(!found){
found=true;
val={num,den};
}else if(num*val.second!=val.first*den){
cout << "NO",exit(0);
}
}
}
}
};
for(int i=0;i<n;i++)if(!vis[i]){
comp.clear();
found=false;
a[i]=1,b[i]=0;
dfs(i);
auto calc=[&](int x){
int res=0;
for(auto u:comp){
res+=abs(a[u]*x+b[u]*2);
}
return res;
};
auto answer=[&](int x){
for(auto u:comp){
ans[u]=a[u]*x+b[u]*2;
}
};
if(found){
answer(val.first*2/val.second);
}else{
int c=comp.size();
int l=-c*2-1,r=c*2+1;
while(r-l>10){
db s=ceil((r-l)*INVPHI);
int l2=r-s,r2=l+s;
if(calc(l2)<calc(r2))r=r2;
else l=l2;
}
pair<int,int> best(calc(r),r);
for(int i=l;i<=r;i++)best=min(best,{calc(i),i});
answer(best.second);
}
}
cout << "YES\n";
for(int i=0;i<n;i++)cout << db(ans[i])/2.0 << " ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
answer = YES |
2 |
Correct |
1 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2812 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Correct |
1 ms |
2652 KB |
answer = YES |
7 |
Correct |
1 ms |
2652 KB |
answer = YES |
8 |
Correct |
1 ms |
2652 KB |
answer = YES |
9 |
Correct |
1 ms |
2652 KB |
answer = NO |
10 |
Correct |
1 ms |
2652 KB |
answer = YES |
11 |
Correct |
1 ms |
2652 KB |
answer = YES |
12 |
Correct |
1 ms |
2648 KB |
answer = NO |
13 |
Correct |
1 ms |
2652 KB |
answer = YES |
14 |
Correct |
2 ms |
2652 KB |
answer = YES |
15 |
Correct |
2 ms |
3060 KB |
answer = YES |
16 |
Correct |
1 ms |
2648 KB |
answer = YES |
17 |
Correct |
1 ms |
2648 KB |
answer = YES |
18 |
Correct |
1 ms |
2652 KB |
answer = YES |
19 |
Correct |
2 ms |
2652 KB |
answer = YES |
20 |
Correct |
1 ms |
2648 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
1 ms |
2652 KB |
answer = NO |
23 |
Correct |
1 ms |
2648 KB |
answer = NO |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
answer = YES |
2 |
Correct |
1 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2812 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Correct |
1 ms |
2652 KB |
answer = YES |
7 |
Correct |
1 ms |
2652 KB |
answer = YES |
8 |
Correct |
1 ms |
2652 KB |
answer = YES |
9 |
Correct |
1 ms |
2652 KB |
answer = NO |
10 |
Correct |
1 ms |
2652 KB |
answer = YES |
11 |
Correct |
1 ms |
2652 KB |
answer = YES |
12 |
Correct |
1 ms |
2648 KB |
answer = NO |
13 |
Correct |
1 ms |
2652 KB |
answer = YES |
14 |
Correct |
2 ms |
2652 KB |
answer = YES |
15 |
Correct |
2 ms |
3060 KB |
answer = YES |
16 |
Correct |
1 ms |
2648 KB |
answer = YES |
17 |
Correct |
1 ms |
2648 KB |
answer = YES |
18 |
Correct |
1 ms |
2652 KB |
answer = YES |
19 |
Correct |
2 ms |
2652 KB |
answer = YES |
20 |
Correct |
1 ms |
2648 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
1 ms |
2652 KB |
answer = NO |
23 |
Correct |
1 ms |
2648 KB |
answer = NO |
24 |
Correct |
1 ms |
2652 KB |
answer = YES |
25 |
Correct |
2 ms |
2652 KB |
answer = YES |
26 |
Correct |
1 ms |
2652 KB |
answer = YES |
27 |
Correct |
2 ms |
2652 KB |
answer = YES |
28 |
Correct |
1 ms |
2652 KB |
answer = YES |
29 |
Correct |
1 ms |
2648 KB |
answer = YES |
30 |
Correct |
1 ms |
2652 KB |
answer = NO |
31 |
Correct |
1 ms |
2652 KB |
answer = YES |
32 |
Correct |
1 ms |
2648 KB |
answer = YES |
33 |
Correct |
2 ms |
2652 KB |
answer = YES |
34 |
Correct |
1 ms |
2652 KB |
answer = YES |
35 |
Correct |
1 ms |
2652 KB |
answer = YES |
36 |
Correct |
1 ms |
2652 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
answer = YES |
2 |
Correct |
1 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2812 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Correct |
1 ms |
2652 KB |
answer = YES |
7 |
Correct |
1 ms |
2652 KB |
answer = YES |
8 |
Correct |
1 ms |
2652 KB |
answer = YES |
9 |
Correct |
1 ms |
2652 KB |
answer = NO |
10 |
Correct |
1 ms |
2652 KB |
answer = YES |
11 |
Correct |
1 ms |
2652 KB |
answer = YES |
12 |
Correct |
1 ms |
2648 KB |
answer = NO |
13 |
Correct |
1 ms |
2652 KB |
answer = YES |
14 |
Correct |
2 ms |
2652 KB |
answer = YES |
15 |
Correct |
2 ms |
3060 KB |
answer = YES |
16 |
Correct |
1 ms |
2648 KB |
answer = YES |
17 |
Correct |
1 ms |
2648 KB |
answer = YES |
18 |
Correct |
1 ms |
2652 KB |
answer = YES |
19 |
Correct |
2 ms |
2652 KB |
answer = YES |
20 |
Correct |
1 ms |
2648 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
1 ms |
2652 KB |
answer = NO |
23 |
Correct |
1 ms |
2648 KB |
answer = NO |
24 |
Correct |
1 ms |
2652 KB |
answer = YES |
25 |
Correct |
2 ms |
2652 KB |
answer = YES |
26 |
Correct |
1 ms |
2652 KB |
answer = YES |
27 |
Correct |
2 ms |
2652 KB |
answer = YES |
28 |
Correct |
1 ms |
2652 KB |
answer = YES |
29 |
Correct |
1 ms |
2648 KB |
answer = YES |
30 |
Correct |
1 ms |
2652 KB |
answer = NO |
31 |
Correct |
1 ms |
2652 KB |
answer = YES |
32 |
Correct |
1 ms |
2648 KB |
answer = YES |
33 |
Correct |
2 ms |
2652 KB |
answer = YES |
34 |
Correct |
1 ms |
2652 KB |
answer = YES |
35 |
Correct |
1 ms |
2652 KB |
answer = YES |
36 |
Correct |
1 ms |
2652 KB |
answer = YES |
37 |
Correct |
2 ms |
2652 KB |
answer = YES |
38 |
Correct |
1 ms |
2652 KB |
answer = YES |
39 |
Correct |
1 ms |
2712 KB |
answer = YES |
40 |
Correct |
2 ms |
2908 KB |
answer = YES |
41 |
Correct |
1 ms |
2908 KB |
answer = NO |
42 |
Correct |
1 ms |
2908 KB |
answer = YES |
43 |
Correct |
3 ms |
2908 KB |
answer = YES |
44 |
Correct |
2 ms |
2908 KB |
answer = YES |
45 |
Correct |
2 ms |
2908 KB |
answer = YES |
46 |
Correct |
2 ms |
2648 KB |
answer = YES |
47 |
Correct |
2 ms |
2908 KB |
answer = YES |
48 |
Correct |
3 ms |
2908 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
answer = YES |
2 |
Correct |
1 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2812 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Correct |
1 ms |
2652 KB |
answer = YES |
7 |
Correct |
1 ms |
2652 KB |
answer = YES |
8 |
Correct |
1 ms |
2652 KB |
answer = YES |
9 |
Correct |
1 ms |
2652 KB |
answer = NO |
10 |
Correct |
1 ms |
2652 KB |
answer = YES |
11 |
Correct |
1 ms |
2652 KB |
answer = YES |
12 |
Correct |
1 ms |
2648 KB |
answer = NO |
13 |
Correct |
1 ms |
2652 KB |
answer = YES |
14 |
Correct |
2 ms |
2652 KB |
answer = YES |
15 |
Correct |
2 ms |
3060 KB |
answer = YES |
16 |
Correct |
1 ms |
2648 KB |
answer = YES |
17 |
Correct |
1 ms |
2648 KB |
answer = YES |
18 |
Correct |
1 ms |
2652 KB |
answer = YES |
19 |
Correct |
2 ms |
2652 KB |
answer = YES |
20 |
Correct |
1 ms |
2648 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
1 ms |
2652 KB |
answer = NO |
23 |
Correct |
1 ms |
2648 KB |
answer = NO |
24 |
Correct |
1 ms |
2652 KB |
answer = YES |
25 |
Correct |
2 ms |
2652 KB |
answer = YES |
26 |
Correct |
1 ms |
2652 KB |
answer = YES |
27 |
Correct |
2 ms |
2652 KB |
answer = YES |
28 |
Correct |
1 ms |
2652 KB |
answer = YES |
29 |
Correct |
1 ms |
2648 KB |
answer = YES |
30 |
Correct |
1 ms |
2652 KB |
answer = NO |
31 |
Correct |
1 ms |
2652 KB |
answer = YES |
32 |
Correct |
1 ms |
2648 KB |
answer = YES |
33 |
Correct |
2 ms |
2652 KB |
answer = YES |
34 |
Correct |
1 ms |
2652 KB |
answer = YES |
35 |
Correct |
1 ms |
2652 KB |
answer = YES |
36 |
Correct |
1 ms |
2652 KB |
answer = YES |
37 |
Correct |
2 ms |
2652 KB |
answer = YES |
38 |
Correct |
1 ms |
2652 KB |
answer = YES |
39 |
Correct |
1 ms |
2712 KB |
answer = YES |
40 |
Correct |
2 ms |
2908 KB |
answer = YES |
41 |
Correct |
1 ms |
2908 KB |
answer = NO |
42 |
Correct |
1 ms |
2908 KB |
answer = YES |
43 |
Correct |
3 ms |
2908 KB |
answer = YES |
44 |
Correct |
2 ms |
2908 KB |
answer = YES |
45 |
Correct |
2 ms |
2908 KB |
answer = YES |
46 |
Correct |
2 ms |
2648 KB |
answer = YES |
47 |
Correct |
2 ms |
2908 KB |
answer = YES |
48 |
Correct |
3 ms |
2908 KB |
answer = YES |
49 |
Correct |
7 ms |
3676 KB |
answer = YES |
50 |
Correct |
6 ms |
4188 KB |
answer = YES |
51 |
Correct |
7 ms |
4056 KB |
answer = YES |
52 |
Correct |
3 ms |
3420 KB |
answer = NO |
53 |
Correct |
2 ms |
2908 KB |
answer = YES |
54 |
Correct |
4 ms |
2904 KB |
answer = YES |
55 |
Correct |
5 ms |
3080 KB |
answer = YES |
56 |
Correct |
7 ms |
3592 KB |
answer = YES |
57 |
Correct |
7 ms |
3672 KB |
answer = YES |
58 |
Correct |
6 ms |
3464 KB |
answer = YES |
59 |
Correct |
6 ms |
3676 KB |
answer = YES |
60 |
Correct |
7 ms |
3672 KB |
answer = YES |
61 |
Correct |
7 ms |
3160 KB |
answer = YES |
62 |
Correct |
36 ms |
9228 KB |
answer = NO |
63 |
Correct |
45 ms |
10068 KB |
answer = YES |
64 |
Correct |
39 ms |
10036 KB |
answer = NO |
65 |
Correct |
45 ms |
9872 KB |
answer = YES |
66 |
Correct |
3 ms |
2908 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
answer = YES |
2 |
Correct |
1 ms |
2652 KB |
answer = YES |
3 |
Correct |
1 ms |
2652 KB |
answer = YES |
4 |
Correct |
1 ms |
2812 KB |
answer = NO |
5 |
Correct |
1 ms |
2652 KB |
answer = YES |
6 |
Correct |
1 ms |
2652 KB |
answer = YES |
7 |
Correct |
1 ms |
2652 KB |
answer = YES |
8 |
Correct |
1 ms |
2652 KB |
answer = YES |
9 |
Correct |
1 ms |
2652 KB |
answer = NO |
10 |
Correct |
1 ms |
2652 KB |
answer = YES |
11 |
Correct |
1 ms |
2652 KB |
answer = YES |
12 |
Correct |
1 ms |
2648 KB |
answer = NO |
13 |
Correct |
1 ms |
2652 KB |
answer = YES |
14 |
Correct |
2 ms |
2652 KB |
answer = YES |
15 |
Correct |
2 ms |
3060 KB |
answer = YES |
16 |
Correct |
1 ms |
2648 KB |
answer = YES |
17 |
Correct |
1 ms |
2648 KB |
answer = YES |
18 |
Correct |
1 ms |
2652 KB |
answer = YES |
19 |
Correct |
2 ms |
2652 KB |
answer = YES |
20 |
Correct |
1 ms |
2648 KB |
answer = YES |
21 |
Correct |
1 ms |
2652 KB |
answer = YES |
22 |
Correct |
1 ms |
2652 KB |
answer = NO |
23 |
Correct |
1 ms |
2648 KB |
answer = NO |
24 |
Correct |
1 ms |
2652 KB |
answer = YES |
25 |
Correct |
2 ms |
2652 KB |
answer = YES |
26 |
Correct |
1 ms |
2652 KB |
answer = YES |
27 |
Correct |
2 ms |
2652 KB |
answer = YES |
28 |
Correct |
1 ms |
2652 KB |
answer = YES |
29 |
Correct |
1 ms |
2648 KB |
answer = YES |
30 |
Correct |
1 ms |
2652 KB |
answer = NO |
31 |
Correct |
1 ms |
2652 KB |
answer = YES |
32 |
Correct |
1 ms |
2648 KB |
answer = YES |
33 |
Correct |
2 ms |
2652 KB |
answer = YES |
34 |
Correct |
1 ms |
2652 KB |
answer = YES |
35 |
Correct |
1 ms |
2652 KB |
answer = YES |
36 |
Correct |
1 ms |
2652 KB |
answer = YES |
37 |
Correct |
2 ms |
2652 KB |
answer = YES |
38 |
Correct |
1 ms |
2652 KB |
answer = YES |
39 |
Correct |
1 ms |
2712 KB |
answer = YES |
40 |
Correct |
2 ms |
2908 KB |
answer = YES |
41 |
Correct |
1 ms |
2908 KB |
answer = NO |
42 |
Correct |
1 ms |
2908 KB |
answer = YES |
43 |
Correct |
3 ms |
2908 KB |
answer = YES |
44 |
Correct |
2 ms |
2908 KB |
answer = YES |
45 |
Correct |
2 ms |
2908 KB |
answer = YES |
46 |
Correct |
2 ms |
2648 KB |
answer = YES |
47 |
Correct |
2 ms |
2908 KB |
answer = YES |
48 |
Correct |
3 ms |
2908 KB |
answer = YES |
49 |
Correct |
7 ms |
3676 KB |
answer = YES |
50 |
Correct |
6 ms |
4188 KB |
answer = YES |
51 |
Correct |
7 ms |
4056 KB |
answer = YES |
52 |
Correct |
3 ms |
3420 KB |
answer = NO |
53 |
Correct |
2 ms |
2908 KB |
answer = YES |
54 |
Correct |
4 ms |
2904 KB |
answer = YES |
55 |
Correct |
5 ms |
3080 KB |
answer = YES |
56 |
Correct |
7 ms |
3592 KB |
answer = YES |
57 |
Correct |
7 ms |
3672 KB |
answer = YES |
58 |
Correct |
6 ms |
3464 KB |
answer = YES |
59 |
Correct |
6 ms |
3676 KB |
answer = YES |
60 |
Correct |
7 ms |
3672 KB |
answer = YES |
61 |
Correct |
7 ms |
3160 KB |
answer = YES |
62 |
Correct |
36 ms |
9228 KB |
answer = NO |
63 |
Correct |
45 ms |
10068 KB |
answer = YES |
64 |
Correct |
39 ms |
10036 KB |
answer = NO |
65 |
Correct |
45 ms |
9872 KB |
answer = YES |
66 |
Correct |
3 ms |
2908 KB |
answer = YES |
67 |
Incorrect |
116 ms |
21276 KB |
participant answer is larger than the answer of jury |
68 |
Halted |
0 ms |
0 KB |
- |