#include <iostream>
#include <algorithm>
#include <vector>
#define MAX 100000
using namespace std;
///ifstream cin ("c.in");
///ofstream cout ("c.out");
vector <pair <int, int>> graph[MAX + 10];
pair <int, double> ans[MAX + 10];
vector <int> nodes;
vector <double> aux;
int visited[MAX + 10], possible, foundX;
double x;
void speedy()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void dfs(int node)
{
if (possible == 1)
{
visited[node] = 1;
nodes.push_back(node);
for (auto it : graph[node])
{
int a = -ans[node].first, b;
if (it.second == 1)
b = 1.0 - ans[node].second;
else
b = 2.0 - ans[node].second;
if (visited[it.first] == 0)
{
ans[it.first] = {a, b};
dfs(it.first);
}
else
if (a == ans[it.first].first && b == ans[it.first].second)
{
}
else
if (a == ans[it.first].first && b != ans[it.first].second)
possible = 0;
else
{
foundX = 1;
x = (ans[it.first].second - b) / (a - ans[it.first].first);
}
}
}
}
int main()
{
speedy();
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
int a, b, c;
cin >> a >> b >> c;
graph[a].push_back({b, c});
graph[b].push_back({a, c});
}
possible = 1;
for (int i = 1; i <= n && possible == 1; i++)
if (visited[i] == 0)
{
ans[i] = {1, 0.0};
foundX = 0;
dfs(i);
if (foundX == 0)
{
for (auto node : nodes)
aux.push_back(-ans[node].first * ans[node].second);
sort(aux.begin(), aux.end());
x = aux[aux.size() / 2];
}
for (auto node : nodes)
ans[node] = {0, ans[node].first * x + ans[node].second};
if (possible == 1)
for (auto node : nodes)
for (auto it : graph[node])
if (ans[node].second + ans[it.first].second != it.second)
possible = 0;
aux.clear();
nodes.clear();
}
if (possible == 1)
{
cout << "YES\n";
for (int i = 1; i <= n; i++)
cout << ans[i].second << ' ';
}
else
cout << "NO\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
1 ms |
2644 KB |
answer = YES |
3 |
Correct |
1 ms |
2644 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
3 ms |
2684 KB |
answer = YES |
7 |
Correct |
1 ms |
2644 KB |
answer = YES |
8 |
Correct |
1 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2688 KB |
answer = NO |
10 |
Correct |
1 ms |
2644 KB |
answer = YES |
11 |
Correct |
1 ms |
2688 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
1 ms |
2644 KB |
answer = YES |
14 |
Correct |
1 ms |
2644 KB |
answer = YES |
15 |
Correct |
1 ms |
2644 KB |
answer = YES |
16 |
Correct |
1 ms |
2644 KB |
answer = YES |
17 |
Correct |
1 ms |
2644 KB |
answer = YES |
18 |
Correct |
2 ms |
2692 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
1 ms |
2644 KB |
answer = YES |
21 |
Correct |
1 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2684 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
1 ms |
2644 KB |
answer = YES |
3 |
Correct |
1 ms |
2644 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
3 ms |
2684 KB |
answer = YES |
7 |
Correct |
1 ms |
2644 KB |
answer = YES |
8 |
Correct |
1 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2688 KB |
answer = NO |
10 |
Correct |
1 ms |
2644 KB |
answer = YES |
11 |
Correct |
1 ms |
2688 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
1 ms |
2644 KB |
answer = YES |
14 |
Correct |
1 ms |
2644 KB |
answer = YES |
15 |
Correct |
1 ms |
2644 KB |
answer = YES |
16 |
Correct |
1 ms |
2644 KB |
answer = YES |
17 |
Correct |
1 ms |
2644 KB |
answer = YES |
18 |
Correct |
2 ms |
2692 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
1 ms |
2644 KB |
answer = YES |
21 |
Correct |
1 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2684 KB |
answer = NO |
24 |
Correct |
2 ms |
2684 KB |
answer = YES |
25 |
Correct |
1 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2644 KB |
answer = YES |
27 |
Correct |
1 ms |
2644 KB |
answer = YES |
28 |
Correct |
1 ms |
2688 KB |
answer = YES |
29 |
Correct |
1 ms |
2692 KB |
answer = YES |
30 |
Correct |
1 ms |
2644 KB |
answer = NO |
31 |
Correct |
1 ms |
2644 KB |
answer = YES |
32 |
Correct |
1 ms |
2644 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
1 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2688 KB |
answer = YES |
36 |
Correct |
1 ms |
2644 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
1 ms |
2644 KB |
answer = YES |
3 |
Correct |
1 ms |
2644 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
3 ms |
2684 KB |
answer = YES |
7 |
Correct |
1 ms |
2644 KB |
answer = YES |
8 |
Correct |
1 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2688 KB |
answer = NO |
10 |
Correct |
1 ms |
2644 KB |
answer = YES |
11 |
Correct |
1 ms |
2688 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
1 ms |
2644 KB |
answer = YES |
14 |
Correct |
1 ms |
2644 KB |
answer = YES |
15 |
Correct |
1 ms |
2644 KB |
answer = YES |
16 |
Correct |
1 ms |
2644 KB |
answer = YES |
17 |
Correct |
1 ms |
2644 KB |
answer = YES |
18 |
Correct |
2 ms |
2692 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
1 ms |
2644 KB |
answer = YES |
21 |
Correct |
1 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2684 KB |
answer = NO |
24 |
Correct |
2 ms |
2684 KB |
answer = YES |
25 |
Correct |
1 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2644 KB |
answer = YES |
27 |
Correct |
1 ms |
2644 KB |
answer = YES |
28 |
Correct |
1 ms |
2688 KB |
answer = YES |
29 |
Correct |
1 ms |
2692 KB |
answer = YES |
30 |
Correct |
1 ms |
2644 KB |
answer = NO |
31 |
Correct |
1 ms |
2644 KB |
answer = YES |
32 |
Correct |
1 ms |
2644 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
1 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2688 KB |
answer = YES |
36 |
Correct |
1 ms |
2644 KB |
answer = YES |
37 |
Correct |
1 ms |
2644 KB |
answer = YES |
38 |
Correct |
2 ms |
2688 KB |
answer = YES |
39 |
Correct |
2 ms |
2644 KB |
answer = YES |
40 |
Correct |
2 ms |
2772 KB |
answer = YES |
41 |
Correct |
2 ms |
2696 KB |
answer = NO |
42 |
Correct |
2 ms |
2704 KB |
answer = YES |
43 |
Correct |
2 ms |
2644 KB |
answer = YES |
44 |
Correct |
2 ms |
2644 KB |
answer = YES |
45 |
Correct |
2 ms |
2696 KB |
answer = YES |
46 |
Correct |
2 ms |
2644 KB |
answer = YES |
47 |
Correct |
2 ms |
2644 KB |
answer = YES |
48 |
Correct |
2 ms |
2688 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
1 ms |
2644 KB |
answer = YES |
3 |
Correct |
1 ms |
2644 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
3 ms |
2684 KB |
answer = YES |
7 |
Correct |
1 ms |
2644 KB |
answer = YES |
8 |
Correct |
1 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2688 KB |
answer = NO |
10 |
Correct |
1 ms |
2644 KB |
answer = YES |
11 |
Correct |
1 ms |
2688 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
1 ms |
2644 KB |
answer = YES |
14 |
Correct |
1 ms |
2644 KB |
answer = YES |
15 |
Correct |
1 ms |
2644 KB |
answer = YES |
16 |
Correct |
1 ms |
2644 KB |
answer = YES |
17 |
Correct |
1 ms |
2644 KB |
answer = YES |
18 |
Correct |
2 ms |
2692 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
1 ms |
2644 KB |
answer = YES |
21 |
Correct |
1 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2684 KB |
answer = NO |
24 |
Correct |
2 ms |
2684 KB |
answer = YES |
25 |
Correct |
1 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2644 KB |
answer = YES |
27 |
Correct |
1 ms |
2644 KB |
answer = YES |
28 |
Correct |
1 ms |
2688 KB |
answer = YES |
29 |
Correct |
1 ms |
2692 KB |
answer = YES |
30 |
Correct |
1 ms |
2644 KB |
answer = NO |
31 |
Correct |
1 ms |
2644 KB |
answer = YES |
32 |
Correct |
1 ms |
2644 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
1 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2688 KB |
answer = YES |
36 |
Correct |
1 ms |
2644 KB |
answer = YES |
37 |
Correct |
1 ms |
2644 KB |
answer = YES |
38 |
Correct |
2 ms |
2688 KB |
answer = YES |
39 |
Correct |
2 ms |
2644 KB |
answer = YES |
40 |
Correct |
2 ms |
2772 KB |
answer = YES |
41 |
Correct |
2 ms |
2696 KB |
answer = NO |
42 |
Correct |
2 ms |
2704 KB |
answer = YES |
43 |
Correct |
2 ms |
2644 KB |
answer = YES |
44 |
Correct |
2 ms |
2644 KB |
answer = YES |
45 |
Correct |
2 ms |
2696 KB |
answer = YES |
46 |
Correct |
2 ms |
2644 KB |
answer = YES |
47 |
Correct |
2 ms |
2644 KB |
answer = YES |
48 |
Correct |
2 ms |
2688 KB |
answer = YES |
49 |
Correct |
7 ms |
3596 KB |
answer = YES |
50 |
Correct |
8 ms |
3796 KB |
answer = YES |
51 |
Correct |
8 ms |
3924 KB |
answer = YES |
52 |
Correct |
4 ms |
3284 KB |
answer = NO |
53 |
Correct |
2 ms |
2692 KB |
answer = YES |
54 |
Correct |
3 ms |
2900 KB |
answer = YES |
55 |
Correct |
5 ms |
3156 KB |
answer = YES |
56 |
Correct |
7 ms |
3596 KB |
answer = YES |
57 |
Correct |
7 ms |
3412 KB |
answer = YES |
58 |
Correct |
9 ms |
3412 KB |
answer = YES |
59 |
Correct |
7 ms |
3284 KB |
answer = YES |
60 |
Correct |
8 ms |
3500 KB |
answer = YES |
61 |
Correct |
4 ms |
3028 KB |
answer = YES |
62 |
Correct |
39 ms |
9676 KB |
answer = NO |
63 |
Correct |
45 ms |
10268 KB |
answer = YES |
64 |
Correct |
43 ms |
10316 KB |
answer = NO |
65 |
Correct |
45 ms |
10316 KB |
answer = YES |
66 |
Correct |
3 ms |
2828 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
1 ms |
2644 KB |
answer = YES |
3 |
Correct |
1 ms |
2644 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
2 ms |
2644 KB |
answer = YES |
6 |
Correct |
3 ms |
2684 KB |
answer = YES |
7 |
Correct |
1 ms |
2644 KB |
answer = YES |
8 |
Correct |
1 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2688 KB |
answer = NO |
10 |
Correct |
1 ms |
2644 KB |
answer = YES |
11 |
Correct |
1 ms |
2688 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
1 ms |
2644 KB |
answer = YES |
14 |
Correct |
1 ms |
2644 KB |
answer = YES |
15 |
Correct |
1 ms |
2644 KB |
answer = YES |
16 |
Correct |
1 ms |
2644 KB |
answer = YES |
17 |
Correct |
1 ms |
2644 KB |
answer = YES |
18 |
Correct |
2 ms |
2692 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
1 ms |
2644 KB |
answer = YES |
21 |
Correct |
1 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2684 KB |
answer = NO |
24 |
Correct |
2 ms |
2684 KB |
answer = YES |
25 |
Correct |
1 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2644 KB |
answer = YES |
27 |
Correct |
1 ms |
2644 KB |
answer = YES |
28 |
Correct |
1 ms |
2688 KB |
answer = YES |
29 |
Correct |
1 ms |
2692 KB |
answer = YES |
30 |
Correct |
1 ms |
2644 KB |
answer = NO |
31 |
Correct |
1 ms |
2644 KB |
answer = YES |
32 |
Correct |
1 ms |
2644 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
1 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2688 KB |
answer = YES |
36 |
Correct |
1 ms |
2644 KB |
answer = YES |
37 |
Correct |
1 ms |
2644 KB |
answer = YES |
38 |
Correct |
2 ms |
2688 KB |
answer = YES |
39 |
Correct |
2 ms |
2644 KB |
answer = YES |
40 |
Correct |
2 ms |
2772 KB |
answer = YES |
41 |
Correct |
2 ms |
2696 KB |
answer = NO |
42 |
Correct |
2 ms |
2704 KB |
answer = YES |
43 |
Correct |
2 ms |
2644 KB |
answer = YES |
44 |
Correct |
2 ms |
2644 KB |
answer = YES |
45 |
Correct |
2 ms |
2696 KB |
answer = YES |
46 |
Correct |
2 ms |
2644 KB |
answer = YES |
47 |
Correct |
2 ms |
2644 KB |
answer = YES |
48 |
Correct |
2 ms |
2688 KB |
answer = YES |
49 |
Correct |
7 ms |
3596 KB |
answer = YES |
50 |
Correct |
8 ms |
3796 KB |
answer = YES |
51 |
Correct |
8 ms |
3924 KB |
answer = YES |
52 |
Correct |
4 ms |
3284 KB |
answer = NO |
53 |
Correct |
2 ms |
2692 KB |
answer = YES |
54 |
Correct |
3 ms |
2900 KB |
answer = YES |
55 |
Correct |
5 ms |
3156 KB |
answer = YES |
56 |
Correct |
7 ms |
3596 KB |
answer = YES |
57 |
Correct |
7 ms |
3412 KB |
answer = YES |
58 |
Correct |
9 ms |
3412 KB |
answer = YES |
59 |
Correct |
7 ms |
3284 KB |
answer = YES |
60 |
Correct |
8 ms |
3500 KB |
answer = YES |
61 |
Correct |
4 ms |
3028 KB |
answer = YES |
62 |
Correct |
39 ms |
9676 KB |
answer = NO |
63 |
Correct |
45 ms |
10268 KB |
answer = YES |
64 |
Correct |
43 ms |
10316 KB |
answer = NO |
65 |
Correct |
45 ms |
10316 KB |
answer = YES |
66 |
Correct |
3 ms |
2828 KB |
answer = YES |
67 |
Correct |
66 ms |
16884 KB |
answer = YES |
68 |
Correct |
60 ms |
16848 KB |
answer = YES |
69 |
Correct |
61 ms |
16040 KB |
answer = YES |
70 |
Correct |
85 ms |
20464 KB |
answer = YES |
71 |
Correct |
62 ms |
16188 KB |
answer = YES |
72 |
Correct |
70 ms |
11216 KB |
answer = YES |
73 |
Correct |
66 ms |
10440 KB |
answer = YES |
74 |
Correct |
52 ms |
10720 KB |
answer = YES |
75 |
Correct |
20 ms |
8876 KB |
answer = NO |
76 |
Correct |
9 ms |
3796 KB |
answer = YES |
77 |
Correct |
17 ms |
4820 KB |
answer = YES |
78 |
Correct |
30 ms |
6504 KB |
answer = YES |
79 |
Correct |
75 ms |
10092 KB |
answer = YES |
80 |
Correct |
46 ms |
11084 KB |
answer = YES |
81 |
Correct |
34 ms |
12852 KB |
answer = NO |
82 |
Correct |
70 ms |
15868 KB |
answer = YES |
83 |
Correct |
78 ms |
16188 KB |
answer = YES |
84 |
Correct |
77 ms |
16968 KB |
answer = YES |
85 |
Correct |
70 ms |
16908 KB |
answer = YES |
86 |
Correct |
63 ms |
16096 KB |
answer = YES |
87 |
Correct |
32 ms |
11328 KB |
answer = NO |
88 |
Correct |
72 ms |
12488 KB |
answer = YES |
89 |
Correct |
68 ms |
9388 KB |
answer = YES |
90 |
Correct |
64 ms |
9348 KB |
answer = YES |
91 |
Correct |
67 ms |
9380 KB |
answer = YES |
92 |
Correct |
36 ms |
6680 KB |
answer = YES |
93 |
Correct |
39 ms |
6544 KB |
answer = YES |
94 |
Correct |
40 ms |
16920 KB |
answer = NO |
95 |
Correct |
28 ms |
9056 KB |
answer = NO |
96 |
Correct |
107 ms |
18108 KB |
answer = YES |
97 |
Correct |
33 ms |
16900 KB |
answer = NO |