#include <bits/stdc++.h>
using namespace std;
const int nx=1e5+5;
int n, m, u, v, w, a[nx], b[nx], f, vs[nx];
double res[nx];
vector<tuple<int, int, int>> d[nx];
vector<int> comp;
set<double> s;
void dfs(int u, int p)
{
vs[u]=1;
comp.push_back(u);
for (auto [v, w, idx]:d[u])
{
if (idx==p) continue;
if (vs[v])
{
int sma=a[u]+a[v], smb=b[u]+b[v];
if (sma==0&&b[u]+b[v]==w) continue;
else if (sma==0&&b[u]+b[v]!=w)
{
f=1;
break;
}
s.insert(((double)(w-smb))/((double)sma));
}
else
{
a[v]=-a[u];
b[v]=w-b[u];
dfs(v, idx);
}
}
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
for (int i=1; i<=m; i++) cin>>u>>v>>w, d[u].push_back({v, w, i}), d[v].push_back({u, w, i});
for (int i=1; i<=n; i++)
{
if (!vs[i])
{
comp.clear();
s.clear();
a[i]=1;
dfs(i, -1);
if (s.size()>1) f=1;
else if (s.size()==1)
{
double vl=*s.begin();
for (auto x:comp) res[x]=a[x]*vl+b[x];
}
else
{
vector<pair<int, int>> v;
for (auto x:comp) if (a[x]!=0) v.push_back({(-b[x])/a[x], x});
sort(v.begin(), v.end());
int md=(v.size())/2;
double t=0;
if (!v.empty()) t=v[md].first;
for (auto x:comp) res[x]=(double)t*a[x]+(double)b[x];
}
}
}
if (f) return cout<<"NO\n", 0;
cout<<"YES\n";
for (int i=1; i<=n; i++) cout<<setprecision(8)<<res[i]<<' ';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
answer = YES |
2 |
Correct |
1 ms |
4700 KB |
answer = YES |
3 |
Correct |
1 ms |
4700 KB |
answer = YES |
4 |
Correct |
1 ms |
4700 KB |
answer = NO |
5 |
Correct |
1 ms |
4700 KB |
answer = YES |
6 |
Correct |
1 ms |
4700 KB |
answer = YES |
7 |
Correct |
1 ms |
4700 KB |
answer = YES |
8 |
Correct |
1 ms |
4700 KB |
answer = YES |
9 |
Correct |
1 ms |
4700 KB |
answer = NO |
10 |
Correct |
1 ms |
4700 KB |
answer = YES |
11 |
Correct |
1 ms |
4700 KB |
answer = YES |
12 |
Correct |
1 ms |
4700 KB |
answer = NO |
13 |
Correct |
2 ms |
4700 KB |
answer = YES |
14 |
Correct |
1 ms |
4700 KB |
answer = YES |
15 |
Correct |
1 ms |
4700 KB |
answer = YES |
16 |
Correct |
1 ms |
4700 KB |
answer = YES |
17 |
Correct |
1 ms |
4700 KB |
answer = YES |
18 |
Correct |
1 ms |
4700 KB |
answer = YES |
19 |
Correct |
1 ms |
4700 KB |
answer = YES |
20 |
Correct |
1 ms |
4700 KB |
answer = YES |
21 |
Correct |
1 ms |
4700 KB |
answer = YES |
22 |
Correct |
1 ms |
2652 KB |
answer = NO |
23 |
Correct |
1 ms |
2652 KB |
answer = NO |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
answer = YES |
2 |
Correct |
1 ms |
4700 KB |
answer = YES |
3 |
Correct |
1 ms |
4700 KB |
answer = YES |
4 |
Correct |
1 ms |
4700 KB |
answer = NO |
5 |
Correct |
1 ms |
4700 KB |
answer = YES |
6 |
Correct |
1 ms |
4700 KB |
answer = YES |
7 |
Correct |
1 ms |
4700 KB |
answer = YES |
8 |
Correct |
1 ms |
4700 KB |
answer = YES |
9 |
Correct |
1 ms |
4700 KB |
answer = NO |
10 |
Correct |
1 ms |
4700 KB |
answer = YES |
11 |
Correct |
1 ms |
4700 KB |
answer = YES |
12 |
Correct |
1 ms |
4700 KB |
answer = NO |
13 |
Correct |
2 ms |
4700 KB |
answer = YES |
14 |
Correct |
1 ms |
4700 KB |
answer = YES |
15 |
Correct |
1 ms |
4700 KB |
answer = YES |
16 |
Correct |
1 ms |
4700 KB |
answer = YES |
17 |
Correct |
1 ms |
4700 KB |
answer = YES |
18 |
Correct |
1 ms |
4700 KB |
answer = YES |
19 |
Correct |
1 ms |
4700 KB |
answer = YES |
20 |
Correct |
1 ms |
4700 KB |
answer = YES |
21 |
Correct |
1 ms |
4700 KB |
answer = YES |
22 |
Correct |
1 ms |
2652 KB |
answer = NO |
23 |
Correct |
1 ms |
2652 KB |
answer = NO |
24 |
Correct |
1 ms |
4696 KB |
answer = YES |
25 |
Correct |
1 ms |
2652 KB |
answer = YES |
26 |
Correct |
1 ms |
4700 KB |
answer = YES |
27 |
Correct |
1 ms |
4700 KB |
answer = YES |
28 |
Correct |
1 ms |
4700 KB |
answer = YES |
29 |
Correct |
1 ms |
4700 KB |
answer = YES |
30 |
Correct |
1 ms |
4700 KB |
answer = NO |
31 |
Correct |
1 ms |
2652 KB |
answer = YES |
32 |
Correct |
1 ms |
4700 KB |
answer = YES |
33 |
Correct |
1 ms |
4700 KB |
answer = YES |
34 |
Correct |
1 ms |
4700 KB |
answer = YES |
35 |
Correct |
1 ms |
4696 KB |
answer = YES |
36 |
Correct |
1 ms |
4700 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
answer = YES |
2 |
Correct |
1 ms |
4700 KB |
answer = YES |
3 |
Correct |
1 ms |
4700 KB |
answer = YES |
4 |
Correct |
1 ms |
4700 KB |
answer = NO |
5 |
Correct |
1 ms |
4700 KB |
answer = YES |
6 |
Correct |
1 ms |
4700 KB |
answer = YES |
7 |
Correct |
1 ms |
4700 KB |
answer = YES |
8 |
Correct |
1 ms |
4700 KB |
answer = YES |
9 |
Correct |
1 ms |
4700 KB |
answer = NO |
10 |
Correct |
1 ms |
4700 KB |
answer = YES |
11 |
Correct |
1 ms |
4700 KB |
answer = YES |
12 |
Correct |
1 ms |
4700 KB |
answer = NO |
13 |
Correct |
2 ms |
4700 KB |
answer = YES |
14 |
Correct |
1 ms |
4700 KB |
answer = YES |
15 |
Correct |
1 ms |
4700 KB |
answer = YES |
16 |
Correct |
1 ms |
4700 KB |
answer = YES |
17 |
Correct |
1 ms |
4700 KB |
answer = YES |
18 |
Correct |
1 ms |
4700 KB |
answer = YES |
19 |
Correct |
1 ms |
4700 KB |
answer = YES |
20 |
Correct |
1 ms |
4700 KB |
answer = YES |
21 |
Correct |
1 ms |
4700 KB |
answer = YES |
22 |
Correct |
1 ms |
2652 KB |
answer = NO |
23 |
Correct |
1 ms |
2652 KB |
answer = NO |
24 |
Correct |
1 ms |
4696 KB |
answer = YES |
25 |
Correct |
1 ms |
2652 KB |
answer = YES |
26 |
Correct |
1 ms |
4700 KB |
answer = YES |
27 |
Correct |
1 ms |
4700 KB |
answer = YES |
28 |
Correct |
1 ms |
4700 KB |
answer = YES |
29 |
Correct |
1 ms |
4700 KB |
answer = YES |
30 |
Correct |
1 ms |
4700 KB |
answer = NO |
31 |
Correct |
1 ms |
2652 KB |
answer = YES |
32 |
Correct |
1 ms |
4700 KB |
answer = YES |
33 |
Correct |
1 ms |
4700 KB |
answer = YES |
34 |
Correct |
1 ms |
4700 KB |
answer = YES |
35 |
Correct |
1 ms |
4696 KB |
answer = YES |
36 |
Correct |
1 ms |
4700 KB |
answer = YES |
37 |
Correct |
1 ms |
4700 KB |
answer = YES |
38 |
Correct |
1 ms |
2652 KB |
answer = YES |
39 |
Correct |
1 ms |
4700 KB |
answer = YES |
40 |
Correct |
1 ms |
2652 KB |
answer = YES |
41 |
Correct |
1 ms |
4700 KB |
answer = NO |
42 |
Correct |
1 ms |
2908 KB |
answer = YES |
43 |
Correct |
1 ms |
2908 KB |
answer = YES |
44 |
Correct |
2 ms |
2652 KB |
answer = YES |
45 |
Correct |
1 ms |
4700 KB |
answer = YES |
46 |
Correct |
1 ms |
2652 KB |
answer = YES |
47 |
Correct |
1 ms |
4700 KB |
answer = YES |
48 |
Correct |
1 ms |
4700 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
answer = YES |
2 |
Correct |
1 ms |
4700 KB |
answer = YES |
3 |
Correct |
1 ms |
4700 KB |
answer = YES |
4 |
Correct |
1 ms |
4700 KB |
answer = NO |
5 |
Correct |
1 ms |
4700 KB |
answer = YES |
6 |
Correct |
1 ms |
4700 KB |
answer = YES |
7 |
Correct |
1 ms |
4700 KB |
answer = YES |
8 |
Correct |
1 ms |
4700 KB |
answer = YES |
9 |
Correct |
1 ms |
4700 KB |
answer = NO |
10 |
Correct |
1 ms |
4700 KB |
answer = YES |
11 |
Correct |
1 ms |
4700 KB |
answer = YES |
12 |
Correct |
1 ms |
4700 KB |
answer = NO |
13 |
Correct |
2 ms |
4700 KB |
answer = YES |
14 |
Correct |
1 ms |
4700 KB |
answer = YES |
15 |
Correct |
1 ms |
4700 KB |
answer = YES |
16 |
Correct |
1 ms |
4700 KB |
answer = YES |
17 |
Correct |
1 ms |
4700 KB |
answer = YES |
18 |
Correct |
1 ms |
4700 KB |
answer = YES |
19 |
Correct |
1 ms |
4700 KB |
answer = YES |
20 |
Correct |
1 ms |
4700 KB |
answer = YES |
21 |
Correct |
1 ms |
4700 KB |
answer = YES |
22 |
Correct |
1 ms |
2652 KB |
answer = NO |
23 |
Correct |
1 ms |
2652 KB |
answer = NO |
24 |
Correct |
1 ms |
4696 KB |
answer = YES |
25 |
Correct |
1 ms |
2652 KB |
answer = YES |
26 |
Correct |
1 ms |
4700 KB |
answer = YES |
27 |
Correct |
1 ms |
4700 KB |
answer = YES |
28 |
Correct |
1 ms |
4700 KB |
answer = YES |
29 |
Correct |
1 ms |
4700 KB |
answer = YES |
30 |
Correct |
1 ms |
4700 KB |
answer = NO |
31 |
Correct |
1 ms |
2652 KB |
answer = YES |
32 |
Correct |
1 ms |
4700 KB |
answer = YES |
33 |
Correct |
1 ms |
4700 KB |
answer = YES |
34 |
Correct |
1 ms |
4700 KB |
answer = YES |
35 |
Correct |
1 ms |
4696 KB |
answer = YES |
36 |
Correct |
1 ms |
4700 KB |
answer = YES |
37 |
Correct |
1 ms |
4700 KB |
answer = YES |
38 |
Correct |
1 ms |
2652 KB |
answer = YES |
39 |
Correct |
1 ms |
4700 KB |
answer = YES |
40 |
Correct |
1 ms |
2652 KB |
answer = YES |
41 |
Correct |
1 ms |
4700 KB |
answer = NO |
42 |
Correct |
1 ms |
2908 KB |
answer = YES |
43 |
Correct |
1 ms |
2908 KB |
answer = YES |
44 |
Correct |
2 ms |
2652 KB |
answer = YES |
45 |
Correct |
1 ms |
4700 KB |
answer = YES |
46 |
Correct |
1 ms |
2652 KB |
answer = YES |
47 |
Correct |
1 ms |
4700 KB |
answer = YES |
48 |
Correct |
1 ms |
4700 KB |
answer = YES |
49 |
Correct |
10 ms |
3672 KB |
answer = YES |
50 |
Correct |
6 ms |
3932 KB |
answer = YES |
51 |
Correct |
7 ms |
5724 KB |
answer = YES |
52 |
Correct |
5 ms |
5740 KB |
answer = NO |
53 |
Correct |
1 ms |
4700 KB |
answer = YES |
54 |
Correct |
2 ms |
4912 KB |
answer = YES |
55 |
Correct |
4 ms |
4956 KB |
answer = YES |
56 |
Correct |
6 ms |
5360 KB |
answer = YES |
57 |
Correct |
6 ms |
3420 KB |
answer = YES |
58 |
Correct |
5 ms |
3420 KB |
answer = YES |
59 |
Correct |
5 ms |
3416 KB |
answer = YES |
60 |
Correct |
6 ms |
5208 KB |
answer = YES |
61 |
Correct |
3 ms |
3164 KB |
answer = YES |
62 |
Correct |
36 ms |
11912 KB |
answer = NO |
63 |
Correct |
41 ms |
10576 KB |
answer = YES |
64 |
Correct |
40 ms |
10400 KB |
answer = NO |
65 |
Correct |
42 ms |
10436 KB |
answer = YES |
66 |
Correct |
2 ms |
4700 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
answer = YES |
2 |
Correct |
1 ms |
4700 KB |
answer = YES |
3 |
Correct |
1 ms |
4700 KB |
answer = YES |
4 |
Correct |
1 ms |
4700 KB |
answer = NO |
5 |
Correct |
1 ms |
4700 KB |
answer = YES |
6 |
Correct |
1 ms |
4700 KB |
answer = YES |
7 |
Correct |
1 ms |
4700 KB |
answer = YES |
8 |
Correct |
1 ms |
4700 KB |
answer = YES |
9 |
Correct |
1 ms |
4700 KB |
answer = NO |
10 |
Correct |
1 ms |
4700 KB |
answer = YES |
11 |
Correct |
1 ms |
4700 KB |
answer = YES |
12 |
Correct |
1 ms |
4700 KB |
answer = NO |
13 |
Correct |
2 ms |
4700 KB |
answer = YES |
14 |
Correct |
1 ms |
4700 KB |
answer = YES |
15 |
Correct |
1 ms |
4700 KB |
answer = YES |
16 |
Correct |
1 ms |
4700 KB |
answer = YES |
17 |
Correct |
1 ms |
4700 KB |
answer = YES |
18 |
Correct |
1 ms |
4700 KB |
answer = YES |
19 |
Correct |
1 ms |
4700 KB |
answer = YES |
20 |
Correct |
1 ms |
4700 KB |
answer = YES |
21 |
Correct |
1 ms |
4700 KB |
answer = YES |
22 |
Correct |
1 ms |
2652 KB |
answer = NO |
23 |
Correct |
1 ms |
2652 KB |
answer = NO |
24 |
Correct |
1 ms |
4696 KB |
answer = YES |
25 |
Correct |
1 ms |
2652 KB |
answer = YES |
26 |
Correct |
1 ms |
4700 KB |
answer = YES |
27 |
Correct |
1 ms |
4700 KB |
answer = YES |
28 |
Correct |
1 ms |
4700 KB |
answer = YES |
29 |
Correct |
1 ms |
4700 KB |
answer = YES |
30 |
Correct |
1 ms |
4700 KB |
answer = NO |
31 |
Correct |
1 ms |
2652 KB |
answer = YES |
32 |
Correct |
1 ms |
4700 KB |
answer = YES |
33 |
Correct |
1 ms |
4700 KB |
answer = YES |
34 |
Correct |
1 ms |
4700 KB |
answer = YES |
35 |
Correct |
1 ms |
4696 KB |
answer = YES |
36 |
Correct |
1 ms |
4700 KB |
answer = YES |
37 |
Correct |
1 ms |
4700 KB |
answer = YES |
38 |
Correct |
1 ms |
2652 KB |
answer = YES |
39 |
Correct |
1 ms |
4700 KB |
answer = YES |
40 |
Correct |
1 ms |
2652 KB |
answer = YES |
41 |
Correct |
1 ms |
4700 KB |
answer = NO |
42 |
Correct |
1 ms |
2908 KB |
answer = YES |
43 |
Correct |
1 ms |
2908 KB |
answer = YES |
44 |
Correct |
2 ms |
2652 KB |
answer = YES |
45 |
Correct |
1 ms |
4700 KB |
answer = YES |
46 |
Correct |
1 ms |
2652 KB |
answer = YES |
47 |
Correct |
1 ms |
4700 KB |
answer = YES |
48 |
Correct |
1 ms |
4700 KB |
answer = YES |
49 |
Correct |
10 ms |
3672 KB |
answer = YES |
50 |
Correct |
6 ms |
3932 KB |
answer = YES |
51 |
Correct |
7 ms |
5724 KB |
answer = YES |
52 |
Correct |
5 ms |
5740 KB |
answer = NO |
53 |
Correct |
1 ms |
4700 KB |
answer = YES |
54 |
Correct |
2 ms |
4912 KB |
answer = YES |
55 |
Correct |
4 ms |
4956 KB |
answer = YES |
56 |
Correct |
6 ms |
5360 KB |
answer = YES |
57 |
Correct |
6 ms |
3420 KB |
answer = YES |
58 |
Correct |
5 ms |
3420 KB |
answer = YES |
59 |
Correct |
5 ms |
3416 KB |
answer = YES |
60 |
Correct |
6 ms |
5208 KB |
answer = YES |
61 |
Correct |
3 ms |
3164 KB |
answer = YES |
62 |
Correct |
36 ms |
11912 KB |
answer = NO |
63 |
Correct |
41 ms |
10576 KB |
answer = YES |
64 |
Correct |
40 ms |
10400 KB |
answer = NO |
65 |
Correct |
42 ms |
10436 KB |
answer = YES |
66 |
Correct |
2 ms |
4700 KB |
answer = YES |
67 |
Correct |
78 ms |
18508 KB |
answer = YES |
68 |
Correct |
74 ms |
19788 KB |
answer = YES |
69 |
Correct |
47 ms |
18896 KB |
answer = YES |
70 |
Correct |
70 ms |
24900 KB |
answer = YES |
71 |
Correct |
55 ms |
19144 KB |
answer = YES |
72 |
Correct |
59 ms |
11344 KB |
answer = YES |
73 |
Correct |
52 ms |
10704 KB |
answer = YES |
74 |
Correct |
35 ms |
12760 KB |
answer = YES |
75 |
Correct |
23 ms |
13008 KB |
answer = NO |
76 |
Correct |
7 ms |
5468 KB |
answer = YES |
77 |
Correct |
14 ms |
6492 KB |
answer = YES |
78 |
Correct |
25 ms |
7876 KB |
answer = YES |
79 |
Correct |
49 ms |
9808 KB |
answer = YES |
80 |
Correct |
41 ms |
12380 KB |
answer = YES |
81 |
Correct |
28 ms |
13040 KB |
answer = NO |
82 |
Correct |
58 ms |
17356 KB |
answer = YES |
83 |
Correct |
79 ms |
18120 KB |
answer = YES |
84 |
Correct |
69 ms |
18764 KB |
answer = YES |
85 |
Correct |
57 ms |
18764 KB |
answer = YES |
86 |
Correct |
50 ms |
18008 KB |
answer = YES |
87 |
Correct |
32 ms |
11112 KB |
answer = NO |
88 |
Correct |
59 ms |
12460 KB |
answer = YES |
89 |
Correct |
52 ms |
8020 KB |
answer = YES |
90 |
Correct |
50 ms |
8016 KB |
answer = YES |
91 |
Correct |
52 ms |
8044 KB |
answer = YES |
92 |
Correct |
29 ms |
6360 KB |
answer = YES |
93 |
Correct |
24 ms |
6356 KB |
answer = YES |
94 |
Correct |
48 ms |
18764 KB |
answer = NO |
95 |
Correct |
27 ms |
7772 KB |
answer = NO |
96 |
Correct |
86 ms |
19148 KB |
answer = YES |
97 |
Correct |
31 ms |
18512 KB |
answer = NO |