/*
بسم الله الرحمن الرحيم
Author:
(:Muhammad Aneeq:)
*/
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
int const N=1e5+10;
vector<pair<int,int>>nei[N]={};
float val[N]={},ansval[N]={};
bitset<N>vis;
vector<vector<int>>f;
float mx=1e9+10;
int n,m;
bool dfs1(int u)
{
for (auto [i,j]:nei[u])
{
if (val[i]==-1e9)
{
val[i]=j-val[u];
if (dfs1(i)==0)
return 0;
}
else if (val[i]+val[u]!=j)
return 0;
}
return 1;
}
void dfs(int x)
{
vis[x]=1;
f.back().push_back(x);
for (auto [i,j]:nei[x])
{
if (!vis[i])
dfs(i);
}
}
inline void solve()
{
cin>>n>>m;
for (int i=0;i<m;i++)
{
int u,v,t;
cin>>u>>v>>t;
nei[u].push_back({v,t});
nei[v].push_back({u,t});
}
for (int i=1;i<=n;i++)
{
if (!vis[i])
{
f.push_back({});
dfs(i);
}
}
for (int i=1;i<=n;i++)
{
val[i]=-1e9;
ansval[i]=-1e9;
}
for (auto i:f)
{
int r=i[0];
float mx=1e9+10;
for (float j=-50;j<=25;j+=0.5)
{
val[r]=j;
if (dfs1(r))
{
float z=0;
for (auto k:i)
z+=abs(val[k]);
if (z<mx)
{
mx=z;
for (auto k:i)
ansval[k]=val[k];
}
}
for (auto k:i)
val[k]=-1e9;
}
if (mx==1e9+10)
{
cout<<"NO\n";return;
}
}
for (int i=1;i<=n;i++)
{
if (ansval[i]==-1e9)
{
cout<<"NO\n";return;
}
}
cout<<"YES\n";
for (int i=1;i<=n;i++)
cout<<ansval[i]<<' ';
cout<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
answer = YES |
2 |
Correct |
1 ms |
3420 KB |
answer = YES |
3 |
Correct |
1 ms |
3420 KB |
answer = YES |
4 |
Correct |
2 ms |
3420 KB |
answer = NO |
5 |
Correct |
1 ms |
3420 KB |
answer = YES |
6 |
Correct |
1 ms |
3420 KB |
answer = YES |
7 |
Correct |
1 ms |
3420 KB |
answer = YES |
8 |
Correct |
1 ms |
3420 KB |
answer = YES |
9 |
Correct |
1 ms |
3420 KB |
answer = NO |
10 |
Correct |
1 ms |
3420 KB |
answer = YES |
11 |
Correct |
1 ms |
3420 KB |
answer = YES |
12 |
Correct |
1 ms |
3420 KB |
answer = NO |
13 |
Correct |
1 ms |
3420 KB |
answer = YES |
14 |
Correct |
1 ms |
3420 KB |
answer = YES |
15 |
Correct |
1 ms |
3420 KB |
answer = YES |
16 |
Correct |
1 ms |
3420 KB |
answer = YES |
17 |
Correct |
1 ms |
3420 KB |
answer = YES |
18 |
Correct |
1 ms |
3420 KB |
answer = YES |
19 |
Correct |
1 ms |
3420 KB |
answer = YES |
20 |
Correct |
1 ms |
3420 KB |
answer = YES |
21 |
Correct |
1 ms |
3420 KB |
answer = YES |
22 |
Correct |
1 ms |
3420 KB |
answer = NO |
23 |
Correct |
2 ms |
3420 KB |
answer = NO |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
answer = YES |
2 |
Correct |
1 ms |
3420 KB |
answer = YES |
3 |
Correct |
1 ms |
3420 KB |
answer = YES |
4 |
Correct |
2 ms |
3420 KB |
answer = NO |
5 |
Correct |
1 ms |
3420 KB |
answer = YES |
6 |
Correct |
1 ms |
3420 KB |
answer = YES |
7 |
Correct |
1 ms |
3420 KB |
answer = YES |
8 |
Correct |
1 ms |
3420 KB |
answer = YES |
9 |
Correct |
1 ms |
3420 KB |
answer = NO |
10 |
Correct |
1 ms |
3420 KB |
answer = YES |
11 |
Correct |
1 ms |
3420 KB |
answer = YES |
12 |
Correct |
1 ms |
3420 KB |
answer = NO |
13 |
Correct |
1 ms |
3420 KB |
answer = YES |
14 |
Correct |
1 ms |
3420 KB |
answer = YES |
15 |
Correct |
1 ms |
3420 KB |
answer = YES |
16 |
Correct |
1 ms |
3420 KB |
answer = YES |
17 |
Correct |
1 ms |
3420 KB |
answer = YES |
18 |
Correct |
1 ms |
3420 KB |
answer = YES |
19 |
Correct |
1 ms |
3420 KB |
answer = YES |
20 |
Correct |
1 ms |
3420 KB |
answer = YES |
21 |
Correct |
1 ms |
3420 KB |
answer = YES |
22 |
Correct |
1 ms |
3420 KB |
answer = NO |
23 |
Correct |
2 ms |
3420 KB |
answer = NO |
24 |
Correct |
1 ms |
3416 KB |
answer = YES |
25 |
Correct |
1 ms |
3420 KB |
answer = YES |
26 |
Correct |
1 ms |
3420 KB |
answer = YES |
27 |
Correct |
1 ms |
3420 KB |
answer = YES |
28 |
Correct |
1 ms |
3420 KB |
answer = YES |
29 |
Correct |
1 ms |
3420 KB |
answer = YES |
30 |
Correct |
1 ms |
3420 KB |
answer = NO |
31 |
Correct |
2 ms |
3420 KB |
answer = YES |
32 |
Correct |
2 ms |
3420 KB |
answer = YES |
33 |
Correct |
1 ms |
3420 KB |
answer = YES |
34 |
Correct |
1 ms |
3420 KB |
answer = YES |
35 |
Correct |
1 ms |
3420 KB |
answer = YES |
36 |
Correct |
2 ms |
3420 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
answer = YES |
2 |
Correct |
1 ms |
3420 KB |
answer = YES |
3 |
Correct |
1 ms |
3420 KB |
answer = YES |
4 |
Correct |
2 ms |
3420 KB |
answer = NO |
5 |
Correct |
1 ms |
3420 KB |
answer = YES |
6 |
Correct |
1 ms |
3420 KB |
answer = YES |
7 |
Correct |
1 ms |
3420 KB |
answer = YES |
8 |
Correct |
1 ms |
3420 KB |
answer = YES |
9 |
Correct |
1 ms |
3420 KB |
answer = NO |
10 |
Correct |
1 ms |
3420 KB |
answer = YES |
11 |
Correct |
1 ms |
3420 KB |
answer = YES |
12 |
Correct |
1 ms |
3420 KB |
answer = NO |
13 |
Correct |
1 ms |
3420 KB |
answer = YES |
14 |
Correct |
1 ms |
3420 KB |
answer = YES |
15 |
Correct |
1 ms |
3420 KB |
answer = YES |
16 |
Correct |
1 ms |
3420 KB |
answer = YES |
17 |
Correct |
1 ms |
3420 KB |
answer = YES |
18 |
Correct |
1 ms |
3420 KB |
answer = YES |
19 |
Correct |
1 ms |
3420 KB |
answer = YES |
20 |
Correct |
1 ms |
3420 KB |
answer = YES |
21 |
Correct |
1 ms |
3420 KB |
answer = YES |
22 |
Correct |
1 ms |
3420 KB |
answer = NO |
23 |
Correct |
2 ms |
3420 KB |
answer = NO |
24 |
Correct |
1 ms |
3416 KB |
answer = YES |
25 |
Correct |
1 ms |
3420 KB |
answer = YES |
26 |
Correct |
1 ms |
3420 KB |
answer = YES |
27 |
Correct |
1 ms |
3420 KB |
answer = YES |
28 |
Correct |
1 ms |
3420 KB |
answer = YES |
29 |
Correct |
1 ms |
3420 KB |
answer = YES |
30 |
Correct |
1 ms |
3420 KB |
answer = NO |
31 |
Correct |
2 ms |
3420 KB |
answer = YES |
32 |
Correct |
2 ms |
3420 KB |
answer = YES |
33 |
Correct |
1 ms |
3420 KB |
answer = YES |
34 |
Correct |
1 ms |
3420 KB |
answer = YES |
35 |
Correct |
1 ms |
3420 KB |
answer = YES |
36 |
Correct |
2 ms |
3420 KB |
answer = YES |
37 |
Correct |
1 ms |
3420 KB |
answer = YES |
38 |
Correct |
1 ms |
3420 KB |
answer = YES |
39 |
Correct |
2 ms |
3420 KB |
answer = YES |
40 |
Correct |
2 ms |
3672 KB |
answer = YES |
41 |
Correct |
2 ms |
3420 KB |
answer = NO |
42 |
Correct |
3 ms |
3420 KB |
answer = YES |
43 |
Correct |
3 ms |
3488 KB |
answer = YES |
44 |
Correct |
3 ms |
3420 KB |
answer = YES |
45 |
Correct |
3 ms |
3420 KB |
answer = YES |
46 |
Correct |
2 ms |
3668 KB |
answer = YES |
47 |
Correct |
2 ms |
3420 KB |
answer = YES |
48 |
Correct |
2 ms |
3420 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
answer = YES |
2 |
Correct |
1 ms |
3420 KB |
answer = YES |
3 |
Correct |
1 ms |
3420 KB |
answer = YES |
4 |
Correct |
2 ms |
3420 KB |
answer = NO |
5 |
Correct |
1 ms |
3420 KB |
answer = YES |
6 |
Correct |
1 ms |
3420 KB |
answer = YES |
7 |
Correct |
1 ms |
3420 KB |
answer = YES |
8 |
Correct |
1 ms |
3420 KB |
answer = YES |
9 |
Correct |
1 ms |
3420 KB |
answer = NO |
10 |
Correct |
1 ms |
3420 KB |
answer = YES |
11 |
Correct |
1 ms |
3420 KB |
answer = YES |
12 |
Correct |
1 ms |
3420 KB |
answer = NO |
13 |
Correct |
1 ms |
3420 KB |
answer = YES |
14 |
Correct |
1 ms |
3420 KB |
answer = YES |
15 |
Correct |
1 ms |
3420 KB |
answer = YES |
16 |
Correct |
1 ms |
3420 KB |
answer = YES |
17 |
Correct |
1 ms |
3420 KB |
answer = YES |
18 |
Correct |
1 ms |
3420 KB |
answer = YES |
19 |
Correct |
1 ms |
3420 KB |
answer = YES |
20 |
Correct |
1 ms |
3420 KB |
answer = YES |
21 |
Correct |
1 ms |
3420 KB |
answer = YES |
22 |
Correct |
1 ms |
3420 KB |
answer = NO |
23 |
Correct |
2 ms |
3420 KB |
answer = NO |
24 |
Correct |
1 ms |
3416 KB |
answer = YES |
25 |
Correct |
1 ms |
3420 KB |
answer = YES |
26 |
Correct |
1 ms |
3420 KB |
answer = YES |
27 |
Correct |
1 ms |
3420 KB |
answer = YES |
28 |
Correct |
1 ms |
3420 KB |
answer = YES |
29 |
Correct |
1 ms |
3420 KB |
answer = YES |
30 |
Correct |
1 ms |
3420 KB |
answer = NO |
31 |
Correct |
2 ms |
3420 KB |
answer = YES |
32 |
Correct |
2 ms |
3420 KB |
answer = YES |
33 |
Correct |
1 ms |
3420 KB |
answer = YES |
34 |
Correct |
1 ms |
3420 KB |
answer = YES |
35 |
Correct |
1 ms |
3420 KB |
answer = YES |
36 |
Correct |
2 ms |
3420 KB |
answer = YES |
37 |
Correct |
1 ms |
3420 KB |
answer = YES |
38 |
Correct |
1 ms |
3420 KB |
answer = YES |
39 |
Correct |
2 ms |
3420 KB |
answer = YES |
40 |
Correct |
2 ms |
3672 KB |
answer = YES |
41 |
Correct |
2 ms |
3420 KB |
answer = NO |
42 |
Correct |
3 ms |
3420 KB |
answer = YES |
43 |
Correct |
3 ms |
3488 KB |
answer = YES |
44 |
Correct |
3 ms |
3420 KB |
answer = YES |
45 |
Correct |
3 ms |
3420 KB |
answer = YES |
46 |
Correct |
2 ms |
3668 KB |
answer = YES |
47 |
Correct |
2 ms |
3420 KB |
answer = YES |
48 |
Correct |
2 ms |
3420 KB |
answer = YES |
49 |
Correct |
33 ms |
3948 KB |
answer = YES |
50 |
Correct |
23 ms |
4188 KB |
answer = YES |
51 |
Correct |
26 ms |
4188 KB |
answer = YES |
52 |
Correct |
7 ms |
4184 KB |
answer = NO |
53 |
Correct |
3 ms |
3420 KB |
answer = YES |
54 |
Correct |
6 ms |
3420 KB |
answer = YES |
55 |
Correct |
12 ms |
3676 KB |
answer = YES |
56 |
Correct |
33 ms |
3932 KB |
answer = YES |
57 |
Correct |
21 ms |
3932 KB |
answer = YES |
58 |
Correct |
19 ms |
3676 KB |
answer = YES |
59 |
Correct |
14 ms |
3888 KB |
answer = YES |
60 |
Correct |
28 ms |
3932 KB |
answer = YES |
61 |
Correct |
9 ms |
3672 KB |
answer = YES |
62 |
Correct |
41 ms |
8548 KB |
answer = NO |
63 |
Correct |
42 ms |
8576 KB |
answer = YES |
64 |
Correct |
37 ms |
8540 KB |
answer = NO |
65 |
Correct |
40 ms |
8616 KB |
answer = YES |
66 |
Correct |
5 ms |
3416 KB |
answer = YES |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
answer = YES |
2 |
Correct |
1 ms |
3420 KB |
answer = YES |
3 |
Correct |
1 ms |
3420 KB |
answer = YES |
4 |
Correct |
2 ms |
3420 KB |
answer = NO |
5 |
Correct |
1 ms |
3420 KB |
answer = YES |
6 |
Correct |
1 ms |
3420 KB |
answer = YES |
7 |
Correct |
1 ms |
3420 KB |
answer = YES |
8 |
Correct |
1 ms |
3420 KB |
answer = YES |
9 |
Correct |
1 ms |
3420 KB |
answer = NO |
10 |
Correct |
1 ms |
3420 KB |
answer = YES |
11 |
Correct |
1 ms |
3420 KB |
answer = YES |
12 |
Correct |
1 ms |
3420 KB |
answer = NO |
13 |
Correct |
1 ms |
3420 KB |
answer = YES |
14 |
Correct |
1 ms |
3420 KB |
answer = YES |
15 |
Correct |
1 ms |
3420 KB |
answer = YES |
16 |
Correct |
1 ms |
3420 KB |
answer = YES |
17 |
Correct |
1 ms |
3420 KB |
answer = YES |
18 |
Correct |
1 ms |
3420 KB |
answer = YES |
19 |
Correct |
1 ms |
3420 KB |
answer = YES |
20 |
Correct |
1 ms |
3420 KB |
answer = YES |
21 |
Correct |
1 ms |
3420 KB |
answer = YES |
22 |
Correct |
1 ms |
3420 KB |
answer = NO |
23 |
Correct |
2 ms |
3420 KB |
answer = NO |
24 |
Correct |
1 ms |
3416 KB |
answer = YES |
25 |
Correct |
1 ms |
3420 KB |
answer = YES |
26 |
Correct |
1 ms |
3420 KB |
answer = YES |
27 |
Correct |
1 ms |
3420 KB |
answer = YES |
28 |
Correct |
1 ms |
3420 KB |
answer = YES |
29 |
Correct |
1 ms |
3420 KB |
answer = YES |
30 |
Correct |
1 ms |
3420 KB |
answer = NO |
31 |
Correct |
2 ms |
3420 KB |
answer = YES |
32 |
Correct |
2 ms |
3420 KB |
answer = YES |
33 |
Correct |
1 ms |
3420 KB |
answer = YES |
34 |
Correct |
1 ms |
3420 KB |
answer = YES |
35 |
Correct |
1 ms |
3420 KB |
answer = YES |
36 |
Correct |
2 ms |
3420 KB |
answer = YES |
37 |
Correct |
1 ms |
3420 KB |
answer = YES |
38 |
Correct |
1 ms |
3420 KB |
answer = YES |
39 |
Correct |
2 ms |
3420 KB |
answer = YES |
40 |
Correct |
2 ms |
3672 KB |
answer = YES |
41 |
Correct |
2 ms |
3420 KB |
answer = NO |
42 |
Correct |
3 ms |
3420 KB |
answer = YES |
43 |
Correct |
3 ms |
3488 KB |
answer = YES |
44 |
Correct |
3 ms |
3420 KB |
answer = YES |
45 |
Correct |
3 ms |
3420 KB |
answer = YES |
46 |
Correct |
2 ms |
3668 KB |
answer = YES |
47 |
Correct |
2 ms |
3420 KB |
answer = YES |
48 |
Correct |
2 ms |
3420 KB |
answer = YES |
49 |
Correct |
33 ms |
3948 KB |
answer = YES |
50 |
Correct |
23 ms |
4188 KB |
answer = YES |
51 |
Correct |
26 ms |
4188 KB |
answer = YES |
52 |
Correct |
7 ms |
4184 KB |
answer = NO |
53 |
Correct |
3 ms |
3420 KB |
answer = YES |
54 |
Correct |
6 ms |
3420 KB |
answer = YES |
55 |
Correct |
12 ms |
3676 KB |
answer = YES |
56 |
Correct |
33 ms |
3932 KB |
answer = YES |
57 |
Correct |
21 ms |
3932 KB |
answer = YES |
58 |
Correct |
19 ms |
3676 KB |
answer = YES |
59 |
Correct |
14 ms |
3888 KB |
answer = YES |
60 |
Correct |
28 ms |
3932 KB |
answer = YES |
61 |
Correct |
9 ms |
3672 KB |
answer = YES |
62 |
Correct |
41 ms |
8548 KB |
answer = NO |
63 |
Correct |
42 ms |
8576 KB |
answer = YES |
64 |
Correct |
37 ms |
8540 KB |
answer = NO |
65 |
Correct |
40 ms |
8616 KB |
answer = YES |
66 |
Correct |
5 ms |
3416 KB |
answer = YES |
67 |
Correct |
187 ms |
13896 KB |
answer = YES |
68 |
Correct |
179 ms |
14024 KB |
answer = YES |
69 |
Correct |
151 ms |
13900 KB |
answer = YES |
70 |
Correct |
228 ms |
17028 KB |
answer = YES |
71 |
Correct |
162 ms |
13900 KB |
answer = YES |
72 |
Correct |
430 ms |
8256 KB |
answer = YES |
73 |
Correct |
221 ms |
8252 KB |
answer = YES |
74 |
Correct |
127 ms |
9628 KB |
answer = YES |
75 |
Correct |
84 ms |
9428 KB |
answer = NO |
76 |
Correct |
41 ms |
4028 KB |
answer = YES |
77 |
Correct |
97 ms |
4656 KB |
answer = YES |
78 |
Correct |
169 ms |
5664 KB |
answer = YES |
79 |
Correct |
361 ms |
7588 KB |
answer = YES |
80 |
Correct |
238 ms |
9424 KB |
answer = YES |
81 |
Correct |
137 ms |
10708 KB |
answer = NO |
82 |
Correct |
208 ms |
13376 KB |
answer = YES |
83 |
Correct |
670 ms |
13888 KB |
answer = YES |
84 |
Execution timed out |
760 ms |
13888 KB |
Time limit exceeded |
85 |
Halted |
0 ms |
0 KB |
- |