# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
447544 |
2021-07-26T17:38:07 Z |
Ozy |
Graph (BOI20_graph) |
C++17 |
|
223 ms |
30916 KB |
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
#define ld long double
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define MAX 100000
#define des first
#define color second
#define par first
#define val second
#define INF 1000000000
lli n,m,a,b,c;
ld xval;
vector<lli> numeros;
vector<pair<lli,lli>> hijos[MAX+2];
pair<lli,ld> estado[MAX+2];
lli visitados[MAX+2];
bool posible;
void solve(lli pos) {
visitados[pos] = 1;
for (auto h : hijos[pos]) {
a = estado[pos].par * (-1);
if (h.color == 1) b = 1 - estado[pos].val;
else b = 2 - estado[pos].val;
if (visitados[h.des] == 0) {
estado[h.des] = {a,b};
if (a == 1) numeros.push_back(-b);
else numeros.push_back(b);
solve(h.des);
}
else {
if (a == estado[h.des].par) {
if (b == estado[h.des].val) continue;
else posible = false;
}
else {
ld x = (h.color - (estado[pos].val + estado[h.des].val))/2;
if (estado[pos].par == -1) x *= -1;
if (xval == INF) xval = x;
if (xval != x) posible = false;
}
}
}
}
void llena(lli pos) {
visitados[pos] = 2;
estado[pos].val += (estado[pos].par * xval);
for (auto h : hijos[pos]) {
if (visitados[h.des] != 2) llena(h.des);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
rep(i,1,m) {
cin >> a >> b >> c;
hijos[a].push_back({b,c});
hijos[b].push_back({a,c});
}
posible = true;
rep(i,1,n) {
if (visitados[i] == 0) {
estado[i] = {1,0};
numeros.clear();
numeros.push_back(0);
xval = INF;
solve(i);
if (!posible) break;
if (xval == INF) {
sort(numeros.begin(),numeros.end());
a = numeros.size()/2;
xval = numeros[a];
}
llena(i);
}
}
if (!posible) cout << "NO\n";
else {
cout << "YES\n";
cout << setprecision(1) << fixed;
rep(i,1,n) cout << estado[i].val << ' ';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
answer = YES |
2 |
Correct |
2 ms |
2672 KB |
answer = YES |
3 |
Correct |
2 ms |
2636 KB |
answer = YES |
4 |
Correct |
2 ms |
2636 KB |
answer = NO |
5 |
Correct |
2 ms |
2636 KB |
answer = YES |
6 |
Correct |
2 ms |
2680 KB |
answer = YES |
7 |
Correct |
2 ms |
2636 KB |
answer = YES |
8 |
Correct |
2 ms |
2636 KB |
answer = YES |
9 |
Correct |
2 ms |
2636 KB |
answer = NO |
10 |
Correct |
2 ms |
2636 KB |
answer = YES |
11 |
Correct |
2 ms |
2636 KB |
answer = YES |
12 |
Correct |
2 ms |
2636 KB |
answer = NO |
13 |
Correct |
2 ms |
2636 KB |
answer = YES |
14 |
Correct |
2 ms |
2636 KB |
answer = YES |
15 |
Correct |
2 ms |
2636 KB |
answer = YES |
16 |
Correct |
2 ms |
2668 KB |
answer = YES |
17 |
Correct |
2 ms |
2636 KB |
answer = YES |
18 |
Correct |
2 ms |
2636 KB |
answer = YES |
19 |
Correct |
2 ms |
2668 KB |
answer = YES |
20 |
Correct |
2 ms |
2636 KB |
answer = YES |
21 |
Correct |
2 ms |
2636 KB |
answer = YES |
22 |
Correct |
2 ms |
2636 KB |
answer = NO |
23 |
Correct |
2 ms |
2636 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
answer = YES |
2 |
Correct |
2 ms |
2672 KB |
answer = YES |
3 |
Correct |
2 ms |
2636 KB |
answer = YES |
4 |
Correct |
2 ms |
2636 KB |
answer = NO |
5 |
Correct |
2 ms |
2636 KB |
answer = YES |
6 |
Correct |
2 ms |
2680 KB |
answer = YES |
7 |
Correct |
2 ms |
2636 KB |
answer = YES |
8 |
Correct |
2 ms |
2636 KB |
answer = YES |
9 |
Correct |
2 ms |
2636 KB |
answer = NO |
10 |
Correct |
2 ms |
2636 KB |
answer = YES |
11 |
Correct |
2 ms |
2636 KB |
answer = YES |
12 |
Correct |
2 ms |
2636 KB |
answer = NO |
13 |
Correct |
2 ms |
2636 KB |
answer = YES |
14 |
Correct |
2 ms |
2636 KB |
answer = YES |
15 |
Correct |
2 ms |
2636 KB |
answer = YES |
16 |
Correct |
2 ms |
2668 KB |
answer = YES |
17 |
Correct |
2 ms |
2636 KB |
answer = YES |
18 |
Correct |
2 ms |
2636 KB |
answer = YES |
19 |
Correct |
2 ms |
2668 KB |
answer = YES |
20 |
Correct |
2 ms |
2636 KB |
answer = YES |
21 |
Correct |
2 ms |
2636 KB |
answer = YES |
22 |
Correct |
2 ms |
2636 KB |
answer = NO |
23 |
Correct |
2 ms |
2636 KB |
answer = NO |
24 |
Correct |
2 ms |
2672 KB |
answer = YES |
25 |
Correct |
2 ms |
2636 KB |
answer = YES |
26 |
Correct |
2 ms |
2636 KB |
answer = YES |
27 |
Correct |
2 ms |
2636 KB |
answer = YES |
28 |
Correct |
2 ms |
2636 KB |
answer = YES |
29 |
Correct |
2 ms |
2636 KB |
answer = YES |
30 |
Correct |
2 ms |
2636 KB |
answer = NO |
31 |
Correct |
2 ms |
2636 KB |
answer = YES |
32 |
Correct |
2 ms |
2636 KB |
answer = YES |
33 |
Correct |
2 ms |
2636 KB |
answer = YES |
34 |
Correct |
2 ms |
2636 KB |
answer = YES |
35 |
Correct |
2 ms |
2636 KB |
answer = YES |
36 |
Correct |
2 ms |
2636 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
answer = YES |
2 |
Correct |
2 ms |
2672 KB |
answer = YES |
3 |
Correct |
2 ms |
2636 KB |
answer = YES |
4 |
Correct |
2 ms |
2636 KB |
answer = NO |
5 |
Correct |
2 ms |
2636 KB |
answer = YES |
6 |
Correct |
2 ms |
2680 KB |
answer = YES |
7 |
Correct |
2 ms |
2636 KB |
answer = YES |
8 |
Correct |
2 ms |
2636 KB |
answer = YES |
9 |
Correct |
2 ms |
2636 KB |
answer = NO |
10 |
Correct |
2 ms |
2636 KB |
answer = YES |
11 |
Correct |
2 ms |
2636 KB |
answer = YES |
12 |
Correct |
2 ms |
2636 KB |
answer = NO |
13 |
Correct |
2 ms |
2636 KB |
answer = YES |
14 |
Correct |
2 ms |
2636 KB |
answer = YES |
15 |
Correct |
2 ms |
2636 KB |
answer = YES |
16 |
Correct |
2 ms |
2668 KB |
answer = YES |
17 |
Correct |
2 ms |
2636 KB |
answer = YES |
18 |
Correct |
2 ms |
2636 KB |
answer = YES |
19 |
Correct |
2 ms |
2668 KB |
answer = YES |
20 |
Correct |
2 ms |
2636 KB |
answer = YES |
21 |
Correct |
2 ms |
2636 KB |
answer = YES |
22 |
Correct |
2 ms |
2636 KB |
answer = NO |
23 |
Correct |
2 ms |
2636 KB |
answer = NO |
24 |
Correct |
2 ms |
2672 KB |
answer = YES |
25 |
Correct |
2 ms |
2636 KB |
answer = YES |
26 |
Correct |
2 ms |
2636 KB |
answer = YES |
27 |
Correct |
2 ms |
2636 KB |
answer = YES |
28 |
Correct |
2 ms |
2636 KB |
answer = YES |
29 |
Correct |
2 ms |
2636 KB |
answer = YES |
30 |
Correct |
2 ms |
2636 KB |
answer = NO |
31 |
Correct |
2 ms |
2636 KB |
answer = YES |
32 |
Correct |
2 ms |
2636 KB |
answer = YES |
33 |
Correct |
2 ms |
2636 KB |
answer = YES |
34 |
Correct |
2 ms |
2636 KB |
answer = YES |
35 |
Correct |
2 ms |
2636 KB |
answer = YES |
36 |
Correct |
2 ms |
2636 KB |
answer = YES |
37 |
Correct |
2 ms |
2636 KB |
answer = YES |
38 |
Correct |
3 ms |
2764 KB |
answer = YES |
39 |
Correct |
2 ms |
2636 KB |
answer = YES |
40 |
Correct |
3 ms |
2764 KB |
answer = YES |
41 |
Correct |
2 ms |
2764 KB |
answer = NO |
42 |
Correct |
3 ms |
2764 KB |
answer = YES |
43 |
Correct |
3 ms |
2764 KB |
answer = YES |
44 |
Correct |
3 ms |
2696 KB |
answer = YES |
45 |
Correct |
3 ms |
2808 KB |
answer = YES |
46 |
Correct |
2 ms |
2712 KB |
answer = YES |
47 |
Correct |
3 ms |
2764 KB |
answer = YES |
48 |
Correct |
3 ms |
2764 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
answer = YES |
2 |
Correct |
2 ms |
2672 KB |
answer = YES |
3 |
Correct |
2 ms |
2636 KB |
answer = YES |
4 |
Correct |
2 ms |
2636 KB |
answer = NO |
5 |
Correct |
2 ms |
2636 KB |
answer = YES |
6 |
Correct |
2 ms |
2680 KB |
answer = YES |
7 |
Correct |
2 ms |
2636 KB |
answer = YES |
8 |
Correct |
2 ms |
2636 KB |
answer = YES |
9 |
Correct |
2 ms |
2636 KB |
answer = NO |
10 |
Correct |
2 ms |
2636 KB |
answer = YES |
11 |
Correct |
2 ms |
2636 KB |
answer = YES |
12 |
Correct |
2 ms |
2636 KB |
answer = NO |
13 |
Correct |
2 ms |
2636 KB |
answer = YES |
14 |
Correct |
2 ms |
2636 KB |
answer = YES |
15 |
Correct |
2 ms |
2636 KB |
answer = YES |
16 |
Correct |
2 ms |
2668 KB |
answer = YES |
17 |
Correct |
2 ms |
2636 KB |
answer = YES |
18 |
Correct |
2 ms |
2636 KB |
answer = YES |
19 |
Correct |
2 ms |
2668 KB |
answer = YES |
20 |
Correct |
2 ms |
2636 KB |
answer = YES |
21 |
Correct |
2 ms |
2636 KB |
answer = YES |
22 |
Correct |
2 ms |
2636 KB |
answer = NO |
23 |
Correct |
2 ms |
2636 KB |
answer = NO |
24 |
Correct |
2 ms |
2672 KB |
answer = YES |
25 |
Correct |
2 ms |
2636 KB |
answer = YES |
26 |
Correct |
2 ms |
2636 KB |
answer = YES |
27 |
Correct |
2 ms |
2636 KB |
answer = YES |
28 |
Correct |
2 ms |
2636 KB |
answer = YES |
29 |
Correct |
2 ms |
2636 KB |
answer = YES |
30 |
Correct |
2 ms |
2636 KB |
answer = NO |
31 |
Correct |
2 ms |
2636 KB |
answer = YES |
32 |
Correct |
2 ms |
2636 KB |
answer = YES |
33 |
Correct |
2 ms |
2636 KB |
answer = YES |
34 |
Correct |
2 ms |
2636 KB |
answer = YES |
35 |
Correct |
2 ms |
2636 KB |
answer = YES |
36 |
Correct |
2 ms |
2636 KB |
answer = YES |
37 |
Correct |
2 ms |
2636 KB |
answer = YES |
38 |
Correct |
3 ms |
2764 KB |
answer = YES |
39 |
Correct |
2 ms |
2636 KB |
answer = YES |
40 |
Correct |
3 ms |
2764 KB |
answer = YES |
41 |
Correct |
2 ms |
2764 KB |
answer = NO |
42 |
Correct |
3 ms |
2764 KB |
answer = YES |
43 |
Correct |
3 ms |
2764 KB |
answer = YES |
44 |
Correct |
3 ms |
2696 KB |
answer = YES |
45 |
Correct |
3 ms |
2808 KB |
answer = YES |
46 |
Correct |
2 ms |
2712 KB |
answer = YES |
47 |
Correct |
3 ms |
2764 KB |
answer = YES |
48 |
Correct |
3 ms |
2764 KB |
answer = YES |
49 |
Correct |
11 ms |
3916 KB |
answer = YES |
50 |
Correct |
13 ms |
4352 KB |
answer = YES |
51 |
Correct |
13 ms |
4428 KB |
answer = YES |
52 |
Correct |
8 ms |
4324 KB |
answer = NO |
53 |
Correct |
3 ms |
2764 KB |
answer = YES |
54 |
Correct |
4 ms |
2892 KB |
answer = YES |
55 |
Correct |
7 ms |
3276 KB |
answer = YES |
56 |
Correct |
12 ms |
3948 KB |
answer = YES |
57 |
Correct |
13 ms |
3728 KB |
answer = YES |
58 |
Correct |
11 ms |
3660 KB |
answer = YES |
59 |
Correct |
11 ms |
3660 KB |
answer = YES |
60 |
Correct |
12 ms |
3868 KB |
answer = YES |
61 |
Correct |
7 ms |
3276 KB |
answer = YES |
62 |
Correct |
81 ms |
15172 KB |
answer = NO |
63 |
Correct |
84 ms |
15200 KB |
answer = YES |
64 |
Correct |
80 ms |
15192 KB |
answer = NO |
65 |
Correct |
85 ms |
15244 KB |
answer = YES |
66 |
Correct |
4 ms |
2808 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
answer = YES |
2 |
Correct |
2 ms |
2672 KB |
answer = YES |
3 |
Correct |
2 ms |
2636 KB |
answer = YES |
4 |
Correct |
2 ms |
2636 KB |
answer = NO |
5 |
Correct |
2 ms |
2636 KB |
answer = YES |
6 |
Correct |
2 ms |
2680 KB |
answer = YES |
7 |
Correct |
2 ms |
2636 KB |
answer = YES |
8 |
Correct |
2 ms |
2636 KB |
answer = YES |
9 |
Correct |
2 ms |
2636 KB |
answer = NO |
10 |
Correct |
2 ms |
2636 KB |
answer = YES |
11 |
Correct |
2 ms |
2636 KB |
answer = YES |
12 |
Correct |
2 ms |
2636 KB |
answer = NO |
13 |
Correct |
2 ms |
2636 KB |
answer = YES |
14 |
Correct |
2 ms |
2636 KB |
answer = YES |
15 |
Correct |
2 ms |
2636 KB |
answer = YES |
16 |
Correct |
2 ms |
2668 KB |
answer = YES |
17 |
Correct |
2 ms |
2636 KB |
answer = YES |
18 |
Correct |
2 ms |
2636 KB |
answer = YES |
19 |
Correct |
2 ms |
2668 KB |
answer = YES |
20 |
Correct |
2 ms |
2636 KB |
answer = YES |
21 |
Correct |
2 ms |
2636 KB |
answer = YES |
22 |
Correct |
2 ms |
2636 KB |
answer = NO |
23 |
Correct |
2 ms |
2636 KB |
answer = NO |
24 |
Correct |
2 ms |
2672 KB |
answer = YES |
25 |
Correct |
2 ms |
2636 KB |
answer = YES |
26 |
Correct |
2 ms |
2636 KB |
answer = YES |
27 |
Correct |
2 ms |
2636 KB |
answer = YES |
28 |
Correct |
2 ms |
2636 KB |
answer = YES |
29 |
Correct |
2 ms |
2636 KB |
answer = YES |
30 |
Correct |
2 ms |
2636 KB |
answer = NO |
31 |
Correct |
2 ms |
2636 KB |
answer = YES |
32 |
Correct |
2 ms |
2636 KB |
answer = YES |
33 |
Correct |
2 ms |
2636 KB |
answer = YES |
34 |
Correct |
2 ms |
2636 KB |
answer = YES |
35 |
Correct |
2 ms |
2636 KB |
answer = YES |
36 |
Correct |
2 ms |
2636 KB |
answer = YES |
37 |
Correct |
2 ms |
2636 KB |
answer = YES |
38 |
Correct |
3 ms |
2764 KB |
answer = YES |
39 |
Correct |
2 ms |
2636 KB |
answer = YES |
40 |
Correct |
3 ms |
2764 KB |
answer = YES |
41 |
Correct |
2 ms |
2764 KB |
answer = NO |
42 |
Correct |
3 ms |
2764 KB |
answer = YES |
43 |
Correct |
3 ms |
2764 KB |
answer = YES |
44 |
Correct |
3 ms |
2696 KB |
answer = YES |
45 |
Correct |
3 ms |
2808 KB |
answer = YES |
46 |
Correct |
2 ms |
2712 KB |
answer = YES |
47 |
Correct |
3 ms |
2764 KB |
answer = YES |
48 |
Correct |
3 ms |
2764 KB |
answer = YES |
49 |
Correct |
11 ms |
3916 KB |
answer = YES |
50 |
Correct |
13 ms |
4352 KB |
answer = YES |
51 |
Correct |
13 ms |
4428 KB |
answer = YES |
52 |
Correct |
8 ms |
4324 KB |
answer = NO |
53 |
Correct |
3 ms |
2764 KB |
answer = YES |
54 |
Correct |
4 ms |
2892 KB |
answer = YES |
55 |
Correct |
7 ms |
3276 KB |
answer = YES |
56 |
Correct |
12 ms |
3948 KB |
answer = YES |
57 |
Correct |
13 ms |
3728 KB |
answer = YES |
58 |
Correct |
11 ms |
3660 KB |
answer = YES |
59 |
Correct |
11 ms |
3660 KB |
answer = YES |
60 |
Correct |
12 ms |
3868 KB |
answer = YES |
61 |
Correct |
7 ms |
3276 KB |
answer = YES |
62 |
Correct |
81 ms |
15172 KB |
answer = NO |
63 |
Correct |
84 ms |
15200 KB |
answer = YES |
64 |
Correct |
80 ms |
15192 KB |
answer = NO |
65 |
Correct |
85 ms |
15244 KB |
answer = YES |
66 |
Correct |
4 ms |
2808 KB |
answer = YES |
67 |
Correct |
108 ms |
23332 KB |
answer = YES |
68 |
Correct |
96 ms |
23292 KB |
answer = YES |
69 |
Correct |
90 ms |
23252 KB |
answer = YES |
70 |
Correct |
142 ms |
30916 KB |
answer = YES |
71 |
Correct |
95 ms |
23224 KB |
answer = YES |
72 |
Correct |
124 ms |
14276 KB |
answer = YES |
73 |
Correct |
138 ms |
14324 KB |
answer = YES |
74 |
Correct |
76 ms |
14940 KB |
answer = YES |
75 |
Correct |
39 ms |
14612 KB |
answer = NO |
76 |
Correct |
13 ms |
4144 KB |
answer = YES |
77 |
Correct |
26 ms |
5652 KB |
answer = YES |
78 |
Correct |
47 ms |
7692 KB |
answer = YES |
79 |
Correct |
107 ms |
12652 KB |
answer = YES |
80 |
Correct |
83 ms |
14912 KB |
answer = YES |
81 |
Correct |
62 ms |
18360 KB |
answer = NO |
82 |
Correct |
122 ms |
22520 KB |
answer = YES |
83 |
Correct |
158 ms |
23988 KB |
answer = YES |
84 |
Correct |
156 ms |
24008 KB |
answer = YES |
85 |
Correct |
104 ms |
23444 KB |
answer = YES |
86 |
Correct |
107 ms |
23320 KB |
answer = YES |
87 |
Correct |
66 ms |
16116 KB |
answer = NO |
88 |
Correct |
148 ms |
18000 KB |
answer = YES |
89 |
Correct |
100 ms |
12996 KB |
answer = YES |
90 |
Correct |
113 ms |
12960 KB |
answer = YES |
91 |
Correct |
111 ms |
13560 KB |
answer = YES |
92 |
Correct |
54 ms |
8560 KB |
answer = YES |
93 |
Correct |
52 ms |
8508 KB |
answer = YES |
94 |
Correct |
79 ms |
23436 KB |
answer = NO |
95 |
Correct |
55 ms |
13152 KB |
answer = NO |
96 |
Correct |
223 ms |
26516 KB |
answer = YES |
97 |
Correct |
61 ms |
22896 KB |
answer = NO |