#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5 + 10;
int n, m;
bool vis[N];
vector<double> poss;
vector<int> path;
vector<pair<int, double>> g[N], loops;
double val[N], ans[N];
long double sm;
void getpath(int v){
vis[v] = 1;
path.push_back(v);
for (auto [u, w] : g[v])
if (!vis[u]) getpath(u);
}
void dfs(int v){
vis[v] = 1;
sm += abs(val[v]);
for (auto [u, w] : g[v]){
if (vis[u]){
if (val[u] == w - val[v])
continue;
val[u] = 1e9;
sm += 1e9;
return;
}
val[u] = w - val[v];
dfs(u);
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i ++){
int u, v, w;
cin >> u >> v >> w;
g[u].push_back({v, w});
g[v].push_back({u, w});
if (u == v)
loops.push_back({v, w});
}
for (auto [v, w] : loops){
if (vis[v]) continue;
path.clear();
getpath(v);
for (int u : path)
vis[u] = 0;
val[v] = w / 2;
dfs(v);
for (int u : path){
ans[u] = val[u];
if (ans[u] >= 1e9){
cout << "NO" << endl;
return 0;
}
}
}
poss.push_back(0);
for (double i = 0; i < 7; i ++){
poss.push_back(i + 0.5);
poss.push_back(i + 1);
}
for (int i = 1; i <= n; i ++){
if (vis[i]) continue;
path.clear();
getpath(i);
double mn = 1e9;
int sz = path.size();
for (int r = 0; r < 12; r ++){
for (double x : poss){
for (int v : path)
vis[v] = 0;
int ind = rng() % sz;
int node = path[ind];
if (!r) node = i;
sm = 0;
val[node] = x;
dfs(node);
if (mn > sm){
mn = sm;
for (int v : path)
ans[v] = val[v];
}
}
}
for (int v : path) vis[v] = 1;
if (mn == 1e9){
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
for (int i = 1; i <= n; i ++)
cout << ans[i] << " ";
cout << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4212 KB |
answer = YES |
2 |
Correct |
2 ms |
4176 KB |
answer = YES |
3 |
Correct |
3 ms |
2640 KB |
answer = YES |
4 |
Correct |
3 ms |
2640 KB |
answer = NO |
5 |
Correct |
2 ms |
4176 KB |
answer = YES |
6 |
Correct |
3 ms |
4344 KB |
answer = YES |
7 |
Correct |
3 ms |
2640 KB |
answer = YES |
8 |
Correct |
2 ms |
2640 KB |
answer = YES |
9 |
Correct |
3 ms |
2640 KB |
answer = NO |
10 |
Correct |
2 ms |
4176 KB |
answer = YES |
11 |
Correct |
2 ms |
4348 KB |
answer = YES |
12 |
Correct |
3 ms |
4176 KB |
answer = NO |
13 |
Correct |
2 ms |
2640 KB |
answer = YES |
14 |
Correct |
2 ms |
2812 KB |
answer = YES |
15 |
Correct |
2 ms |
4208 KB |
answer = YES |
16 |
Correct |
3 ms |
2912 KB |
answer = YES |
17 |
Correct |
2 ms |
2640 KB |
answer = YES |
18 |
Correct |
3 ms |
2640 KB |
answer = YES |
19 |
Correct |
3 ms |
2640 KB |
answer = YES |
20 |
Correct |
3 ms |
2640 KB |
answer = YES |
21 |
Correct |
2 ms |
4176 KB |
answer = YES |
22 |
Correct |
2 ms |
2640 KB |
answer = NO |
23 |
Correct |
3 ms |
4176 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4212 KB |
answer = YES |
2 |
Correct |
2 ms |
4176 KB |
answer = YES |
3 |
Correct |
3 ms |
2640 KB |
answer = YES |
4 |
Correct |
3 ms |
2640 KB |
answer = NO |
5 |
Correct |
2 ms |
4176 KB |
answer = YES |
6 |
Correct |
3 ms |
4344 KB |
answer = YES |
7 |
Correct |
3 ms |
2640 KB |
answer = YES |
8 |
Correct |
2 ms |
2640 KB |
answer = YES |
9 |
Correct |
3 ms |
2640 KB |
answer = NO |
10 |
Correct |
2 ms |
4176 KB |
answer = YES |
11 |
Correct |
2 ms |
4348 KB |
answer = YES |
12 |
Correct |
3 ms |
4176 KB |
answer = NO |
13 |
Correct |
2 ms |
2640 KB |
answer = YES |
14 |
Correct |
2 ms |
2812 KB |
answer = YES |
15 |
Correct |
2 ms |
4208 KB |
answer = YES |
16 |
Correct |
3 ms |
2912 KB |
answer = YES |
17 |
Correct |
2 ms |
2640 KB |
answer = YES |
18 |
Correct |
3 ms |
2640 KB |
answer = YES |
19 |
Correct |
3 ms |
2640 KB |
answer = YES |
20 |
Correct |
3 ms |
2640 KB |
answer = YES |
21 |
Correct |
2 ms |
4176 KB |
answer = YES |
22 |
Correct |
2 ms |
2640 KB |
answer = NO |
23 |
Correct |
3 ms |
4176 KB |
answer = NO |
24 |
Correct |
2 ms |
4176 KB |
answer = YES |
25 |
Correct |
2 ms |
4176 KB |
answer = YES |
26 |
Correct |
3 ms |
2640 KB |
answer = YES |
27 |
Correct |
3 ms |
4176 KB |
answer = YES |
28 |
Correct |
3 ms |
2640 KB |
answer = YES |
29 |
Correct |
3 ms |
2640 KB |
answer = YES |
30 |
Correct |
2 ms |
4348 KB |
answer = NO |
31 |
Correct |
2 ms |
4176 KB |
answer = YES |
32 |
Correct |
2 ms |
2640 KB |
answer = YES |
33 |
Correct |
3 ms |
2640 KB |
answer = YES |
34 |
Correct |
3 ms |
2640 KB |
answer = YES |
35 |
Correct |
2 ms |
4392 KB |
answer = YES |
36 |
Correct |
2 ms |
4176 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4212 KB |
answer = YES |
2 |
Correct |
2 ms |
4176 KB |
answer = YES |
3 |
Correct |
3 ms |
2640 KB |
answer = YES |
4 |
Correct |
3 ms |
2640 KB |
answer = NO |
5 |
Correct |
2 ms |
4176 KB |
answer = YES |
6 |
Correct |
3 ms |
4344 KB |
answer = YES |
7 |
Correct |
3 ms |
2640 KB |
answer = YES |
8 |
Correct |
2 ms |
2640 KB |
answer = YES |
9 |
Correct |
3 ms |
2640 KB |
answer = NO |
10 |
Correct |
2 ms |
4176 KB |
answer = YES |
11 |
Correct |
2 ms |
4348 KB |
answer = YES |
12 |
Correct |
3 ms |
4176 KB |
answer = NO |
13 |
Correct |
2 ms |
2640 KB |
answer = YES |
14 |
Correct |
2 ms |
2812 KB |
answer = YES |
15 |
Correct |
2 ms |
4208 KB |
answer = YES |
16 |
Correct |
3 ms |
2912 KB |
answer = YES |
17 |
Correct |
2 ms |
2640 KB |
answer = YES |
18 |
Correct |
3 ms |
2640 KB |
answer = YES |
19 |
Correct |
3 ms |
2640 KB |
answer = YES |
20 |
Correct |
3 ms |
2640 KB |
answer = YES |
21 |
Correct |
2 ms |
4176 KB |
answer = YES |
22 |
Correct |
2 ms |
2640 KB |
answer = NO |
23 |
Correct |
3 ms |
4176 KB |
answer = NO |
24 |
Correct |
2 ms |
4176 KB |
answer = YES |
25 |
Correct |
2 ms |
4176 KB |
answer = YES |
26 |
Correct |
3 ms |
2640 KB |
answer = YES |
27 |
Correct |
3 ms |
4176 KB |
answer = YES |
28 |
Correct |
3 ms |
2640 KB |
answer = YES |
29 |
Correct |
3 ms |
2640 KB |
answer = YES |
30 |
Correct |
2 ms |
4348 KB |
answer = NO |
31 |
Correct |
2 ms |
4176 KB |
answer = YES |
32 |
Correct |
2 ms |
2640 KB |
answer = YES |
33 |
Correct |
3 ms |
2640 KB |
answer = YES |
34 |
Correct |
3 ms |
2640 KB |
answer = YES |
35 |
Correct |
2 ms |
4392 KB |
answer = YES |
36 |
Correct |
2 ms |
4176 KB |
answer = YES |
37 |
Correct |
3 ms |
2640 KB |
answer = YES |
38 |
Correct |
3 ms |
2640 KB |
answer = YES |
39 |
Correct |
4 ms |
2640 KB |
answer = YES |
40 |
Correct |
4 ms |
2896 KB |
answer = YES |
41 |
Correct |
4 ms |
4176 KB |
answer = NO |
42 |
Correct |
5 ms |
4176 KB |
answer = YES |
43 |
Correct |
5 ms |
2896 KB |
answer = YES |
44 |
Correct |
5 ms |
4220 KB |
answer = YES |
45 |
Correct |
3 ms |
4176 KB |
answer = YES |
46 |
Correct |
3 ms |
4176 KB |
answer = YES |
47 |
Correct |
3 ms |
4176 KB |
answer = YES |
48 |
Correct |
3 ms |
4176 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4212 KB |
answer = YES |
2 |
Correct |
2 ms |
4176 KB |
answer = YES |
3 |
Correct |
3 ms |
2640 KB |
answer = YES |
4 |
Correct |
3 ms |
2640 KB |
answer = NO |
5 |
Correct |
2 ms |
4176 KB |
answer = YES |
6 |
Correct |
3 ms |
4344 KB |
answer = YES |
7 |
Correct |
3 ms |
2640 KB |
answer = YES |
8 |
Correct |
2 ms |
2640 KB |
answer = YES |
9 |
Correct |
3 ms |
2640 KB |
answer = NO |
10 |
Correct |
2 ms |
4176 KB |
answer = YES |
11 |
Correct |
2 ms |
4348 KB |
answer = YES |
12 |
Correct |
3 ms |
4176 KB |
answer = NO |
13 |
Correct |
2 ms |
2640 KB |
answer = YES |
14 |
Correct |
2 ms |
2812 KB |
answer = YES |
15 |
Correct |
2 ms |
4208 KB |
answer = YES |
16 |
Correct |
3 ms |
2912 KB |
answer = YES |
17 |
Correct |
2 ms |
2640 KB |
answer = YES |
18 |
Correct |
3 ms |
2640 KB |
answer = YES |
19 |
Correct |
3 ms |
2640 KB |
answer = YES |
20 |
Correct |
3 ms |
2640 KB |
answer = YES |
21 |
Correct |
2 ms |
4176 KB |
answer = YES |
22 |
Correct |
2 ms |
2640 KB |
answer = NO |
23 |
Correct |
3 ms |
4176 KB |
answer = NO |
24 |
Correct |
2 ms |
4176 KB |
answer = YES |
25 |
Correct |
2 ms |
4176 KB |
answer = YES |
26 |
Correct |
3 ms |
2640 KB |
answer = YES |
27 |
Correct |
3 ms |
4176 KB |
answer = YES |
28 |
Correct |
3 ms |
2640 KB |
answer = YES |
29 |
Correct |
3 ms |
2640 KB |
answer = YES |
30 |
Correct |
2 ms |
4348 KB |
answer = NO |
31 |
Correct |
2 ms |
4176 KB |
answer = YES |
32 |
Correct |
2 ms |
2640 KB |
answer = YES |
33 |
Correct |
3 ms |
2640 KB |
answer = YES |
34 |
Correct |
3 ms |
2640 KB |
answer = YES |
35 |
Correct |
2 ms |
4392 KB |
answer = YES |
36 |
Correct |
2 ms |
4176 KB |
answer = YES |
37 |
Correct |
3 ms |
2640 KB |
answer = YES |
38 |
Correct |
3 ms |
2640 KB |
answer = YES |
39 |
Correct |
4 ms |
2640 KB |
answer = YES |
40 |
Correct |
4 ms |
2896 KB |
answer = YES |
41 |
Correct |
4 ms |
4176 KB |
answer = NO |
42 |
Correct |
5 ms |
4176 KB |
answer = YES |
43 |
Correct |
5 ms |
2896 KB |
answer = YES |
44 |
Correct |
5 ms |
4220 KB |
answer = YES |
45 |
Correct |
3 ms |
4176 KB |
answer = YES |
46 |
Correct |
3 ms |
4176 KB |
answer = YES |
47 |
Correct |
3 ms |
4176 KB |
answer = YES |
48 |
Correct |
3 ms |
4176 KB |
answer = YES |
49 |
Correct |
40 ms |
5024 KB |
answer = YES |
50 |
Correct |
40 ms |
5448 KB |
answer = YES |
51 |
Correct |
38 ms |
5200 KB |
answer = YES |
52 |
Correct |
39 ms |
5316 KB |
answer = NO |
53 |
Correct |
4 ms |
4176 KB |
answer = YES |
54 |
Correct |
8 ms |
4176 KB |
answer = YES |
55 |
Correct |
15 ms |
4484 KB |
answer = YES |
56 |
Correct |
40 ms |
4944 KB |
answer = YES |
57 |
Correct |
30 ms |
5200 KB |
answer = YES |
58 |
Correct |
25 ms |
4688 KB |
answer = YES |
59 |
Correct |
7 ms |
4944 KB |
answer = YES |
60 |
Correct |
34 ms |
4944 KB |
answer = YES |
61 |
Correct |
5 ms |
4444 KB |
answer = YES |
62 |
Correct |
44 ms |
16028 KB |
answer = NO |
63 |
Correct |
50 ms |
16208 KB |
answer = YES |
64 |
Correct |
46 ms |
16200 KB |
answer = NO |
65 |
Correct |
47 ms |
16212 KB |
answer = YES |
66 |
Correct |
7 ms |
4176 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4212 KB |
answer = YES |
2 |
Correct |
2 ms |
4176 KB |
answer = YES |
3 |
Correct |
3 ms |
2640 KB |
answer = YES |
4 |
Correct |
3 ms |
2640 KB |
answer = NO |
5 |
Correct |
2 ms |
4176 KB |
answer = YES |
6 |
Correct |
3 ms |
4344 KB |
answer = YES |
7 |
Correct |
3 ms |
2640 KB |
answer = YES |
8 |
Correct |
2 ms |
2640 KB |
answer = YES |
9 |
Correct |
3 ms |
2640 KB |
answer = NO |
10 |
Correct |
2 ms |
4176 KB |
answer = YES |
11 |
Correct |
2 ms |
4348 KB |
answer = YES |
12 |
Correct |
3 ms |
4176 KB |
answer = NO |
13 |
Correct |
2 ms |
2640 KB |
answer = YES |
14 |
Correct |
2 ms |
2812 KB |
answer = YES |
15 |
Correct |
2 ms |
4208 KB |
answer = YES |
16 |
Correct |
3 ms |
2912 KB |
answer = YES |
17 |
Correct |
2 ms |
2640 KB |
answer = YES |
18 |
Correct |
3 ms |
2640 KB |
answer = YES |
19 |
Correct |
3 ms |
2640 KB |
answer = YES |
20 |
Correct |
3 ms |
2640 KB |
answer = YES |
21 |
Correct |
2 ms |
4176 KB |
answer = YES |
22 |
Correct |
2 ms |
2640 KB |
answer = NO |
23 |
Correct |
3 ms |
4176 KB |
answer = NO |
24 |
Correct |
2 ms |
4176 KB |
answer = YES |
25 |
Correct |
2 ms |
4176 KB |
answer = YES |
26 |
Correct |
3 ms |
2640 KB |
answer = YES |
27 |
Correct |
3 ms |
4176 KB |
answer = YES |
28 |
Correct |
3 ms |
2640 KB |
answer = YES |
29 |
Correct |
3 ms |
2640 KB |
answer = YES |
30 |
Correct |
2 ms |
4348 KB |
answer = NO |
31 |
Correct |
2 ms |
4176 KB |
answer = YES |
32 |
Correct |
2 ms |
2640 KB |
answer = YES |
33 |
Correct |
3 ms |
2640 KB |
answer = YES |
34 |
Correct |
3 ms |
2640 KB |
answer = YES |
35 |
Correct |
2 ms |
4392 KB |
answer = YES |
36 |
Correct |
2 ms |
4176 KB |
answer = YES |
37 |
Correct |
3 ms |
2640 KB |
answer = YES |
38 |
Correct |
3 ms |
2640 KB |
answer = YES |
39 |
Correct |
4 ms |
2640 KB |
answer = YES |
40 |
Correct |
4 ms |
2896 KB |
answer = YES |
41 |
Correct |
4 ms |
4176 KB |
answer = NO |
42 |
Correct |
5 ms |
4176 KB |
answer = YES |
43 |
Correct |
5 ms |
2896 KB |
answer = YES |
44 |
Correct |
5 ms |
4220 KB |
answer = YES |
45 |
Correct |
3 ms |
4176 KB |
answer = YES |
46 |
Correct |
3 ms |
4176 KB |
answer = YES |
47 |
Correct |
3 ms |
4176 KB |
answer = YES |
48 |
Correct |
3 ms |
4176 KB |
answer = YES |
49 |
Correct |
40 ms |
5024 KB |
answer = YES |
50 |
Correct |
40 ms |
5448 KB |
answer = YES |
51 |
Correct |
38 ms |
5200 KB |
answer = YES |
52 |
Correct |
39 ms |
5316 KB |
answer = NO |
53 |
Correct |
4 ms |
4176 KB |
answer = YES |
54 |
Correct |
8 ms |
4176 KB |
answer = YES |
55 |
Correct |
15 ms |
4484 KB |
answer = YES |
56 |
Correct |
40 ms |
4944 KB |
answer = YES |
57 |
Correct |
30 ms |
5200 KB |
answer = YES |
58 |
Correct |
25 ms |
4688 KB |
answer = YES |
59 |
Correct |
7 ms |
4944 KB |
answer = YES |
60 |
Correct |
34 ms |
4944 KB |
answer = YES |
61 |
Correct |
5 ms |
4444 KB |
answer = YES |
62 |
Correct |
44 ms |
16028 KB |
answer = NO |
63 |
Correct |
50 ms |
16208 KB |
answer = YES |
64 |
Correct |
46 ms |
16200 KB |
answer = NO |
65 |
Correct |
47 ms |
16212 KB |
answer = YES |
66 |
Correct |
7 ms |
4176 KB |
answer = YES |
67 |
Correct |
266 ms |
17612 KB |
answer = YES |
68 |
Correct |
263 ms |
17344 KB |
answer = YES |
69 |
Correct |
271 ms |
17344 KB |
answer = YES |
70 |
Correct |
421 ms |
24976 KB |
answer = YES |
71 |
Correct |
286 ms |
17600 KB |
answer = YES |
72 |
Correct |
632 ms |
11476 KB |
answer = YES |
73 |
Correct |
624 ms |
11476 KB |
answer = YES |
74 |
Incorrect |
292 ms |
12232 KB |
jury has the better answer: jans = YES, pans = NO |
75 |
Halted |
0 ms |
0 KB |
- |