# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
725066 |
2023-04-16T17:21:02 Z |
_martynas |
Graph (BOI20_graph) |
C++11 |
|
251 ms |
20932 KB |
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define all(a) (a).begin(), (a).end()
using pii = pair<int, int>;
using vi = vector<int>;
// a*x+b
struct LinearEq {
double a, b;
};
const int MXN = 1e5+5;
const double EPS = 1e-6;
int n, m;
vector<pii> adj[MXN];
bool visited[MXN];
LinearEq leq[MXN];
double X[MXN];
bool bad = false;
double x = -1.1e9;
vi comp;
void dfs(int u) {
comp.PB(u);
for(auto e : adj[u]) {
int v = e.F; double w = e.S;
if(visited[v]) {
if(abs(leq[v].a)<EPS) {
// v is known
double xx = (w-(leq[u].b+leq[v].b))/leq[u].a;
if(x > -1e9 && abs(x-xx) > EPS) bad = true;
x = xx;
continue;
}
if(abs(leq[u].a-leq[v].a)>EPS) {
if(abs(w-(leq[u].b+leq[v].b)) > EPS) {
bad = true;
}
}
else {
double xx = (w-(leq[u].b+leq[v].b))/(leq[u].a+leq[v].a);
if(x > -1e9 && abs(x-xx) > EPS) bad = true;
x = xx;
}
}
else {
leq[v].a = -leq[u].a;
leq[v].b = w-leq[u].b;
visited[v] = true;
dfs(v);
}
}
}
int main() {
cin >> n >> m;
for(int i = 0; i < m; i++) {
int a, b, c; cin >> a >> b >> c;
adj[a].PB({b, c});
adj[b].PB({a, c});
}
for(int i = 1; i <= n; i++) {
sort(all(adj[i]));
for(int j = 1; j < adj[i].size(); j++) {
if(adj[i][j].F == adj[i][j-1].F && adj[i][j].S != adj[i][j-1].S) {
cout << "NO\n";
return 0;
}
if(adj[i][j].F == i) {
visited[i] = true;
X[i] = 0.5*adj[i][j].S;
leq[i].b = X[i];
}
}
}
for(int i = 1; i <= n; i++) {
if(visited[i]) continue;
visited[i] = true;
leq[i] = {1, 0};
x = -1.1e9;
comp.clear();
dfs(i);
if(bad) {
cout << "NO\n";
return 0;
}
if(x < -1e9) {
// if there was at least one known value all of the component would be known
vector<double> vec;
for(int u : comp) {
vec.PB(-leq[u].a*leq[u].b);
}
sort(all(vec));
x = vec[vec.size()/2];
}
for(int u : comp) {
X[u] = leq[u].a*x+leq[u].b;
}
}
cout << "YES\n";
for(int i = 1; i <= n; i++) {
cout << X[i] << " \n"[i == n];
}
return 0;
}
Compilation message
Graph.cpp: In function 'int main()':
Graph.cpp:72:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(int j = 1; j < adj[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2644 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2656 KB |
answer = NO |
5 |
Correct |
2 ms |
2656 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2664 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2656 KB |
answer = YES |
14 |
Correct |
1 ms |
2660 KB |
answer = YES |
15 |
Correct |
2 ms |
2644 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2656 KB |
answer = YES |
18 |
Correct |
2 ms |
2660 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2644 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2644 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2656 KB |
answer = NO |
5 |
Correct |
2 ms |
2656 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2664 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2656 KB |
answer = YES |
14 |
Correct |
1 ms |
2660 KB |
answer = YES |
15 |
Correct |
2 ms |
2644 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2656 KB |
answer = YES |
18 |
Correct |
2 ms |
2660 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2644 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
2 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2676 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
2 ms |
2660 KB |
answer = YES |
30 |
Correct |
2 ms |
2644 KB |
answer = NO |
31 |
Correct |
2 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2644 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
2 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
2 ms |
2644 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2644 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2656 KB |
answer = NO |
5 |
Correct |
2 ms |
2656 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2664 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2656 KB |
answer = YES |
14 |
Correct |
1 ms |
2660 KB |
answer = YES |
15 |
Correct |
2 ms |
2644 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2656 KB |
answer = YES |
18 |
Correct |
2 ms |
2660 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2644 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
2 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2676 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
2 ms |
2660 KB |
answer = YES |
30 |
Correct |
2 ms |
2644 KB |
answer = NO |
31 |
Correct |
2 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2644 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
2 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
2 ms |
2644 KB |
answer = YES |
37 |
Correct |
2 ms |
2644 KB |
answer = YES |
38 |
Correct |
2 ms |
2660 KB |
answer = YES |
39 |
Correct |
2 ms |
2644 KB |
answer = YES |
40 |
Correct |
3 ms |
2644 KB |
answer = YES |
41 |
Correct |
3 ms |
2644 KB |
answer = NO |
42 |
Correct |
2 ms |
2668 KB |
answer = YES |
43 |
Correct |
3 ms |
2644 KB |
answer = YES |
44 |
Correct |
3 ms |
2644 KB |
answer = YES |
45 |
Correct |
4 ms |
2668 KB |
answer = YES |
46 |
Correct |
2 ms |
2644 KB |
answer = YES |
47 |
Correct |
3 ms |
2644 KB |
answer = YES |
48 |
Correct |
2 ms |
2644 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2644 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2656 KB |
answer = NO |
5 |
Correct |
2 ms |
2656 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2664 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2656 KB |
answer = YES |
14 |
Correct |
1 ms |
2660 KB |
answer = YES |
15 |
Correct |
2 ms |
2644 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2656 KB |
answer = YES |
18 |
Correct |
2 ms |
2660 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2644 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
2 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2676 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
2 ms |
2660 KB |
answer = YES |
30 |
Correct |
2 ms |
2644 KB |
answer = NO |
31 |
Correct |
2 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2644 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
2 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
2 ms |
2644 KB |
answer = YES |
37 |
Correct |
2 ms |
2644 KB |
answer = YES |
38 |
Correct |
2 ms |
2660 KB |
answer = YES |
39 |
Correct |
2 ms |
2644 KB |
answer = YES |
40 |
Correct |
3 ms |
2644 KB |
answer = YES |
41 |
Correct |
3 ms |
2644 KB |
answer = NO |
42 |
Correct |
2 ms |
2668 KB |
answer = YES |
43 |
Correct |
3 ms |
2644 KB |
answer = YES |
44 |
Correct |
3 ms |
2644 KB |
answer = YES |
45 |
Correct |
4 ms |
2668 KB |
answer = YES |
46 |
Correct |
2 ms |
2644 KB |
answer = YES |
47 |
Correct |
3 ms |
2644 KB |
answer = YES |
48 |
Correct |
2 ms |
2644 KB |
answer = YES |
49 |
Correct |
13 ms |
3600 KB |
answer = YES |
50 |
Correct |
17 ms |
3824 KB |
answer = YES |
51 |
Correct |
14 ms |
3936 KB |
answer = YES |
52 |
Correct |
11 ms |
3696 KB |
answer = NO |
53 |
Correct |
4 ms |
2644 KB |
answer = YES |
54 |
Correct |
4 ms |
2848 KB |
answer = YES |
55 |
Correct |
8 ms |
3156 KB |
answer = YES |
56 |
Correct |
14 ms |
3568 KB |
answer = YES |
57 |
Correct |
14 ms |
3540 KB |
answer = YES |
58 |
Correct |
13 ms |
3436 KB |
answer = YES |
59 |
Correct |
14 ms |
3412 KB |
answer = YES |
60 |
Correct |
14 ms |
3436 KB |
answer = YES |
61 |
Correct |
10 ms |
3100 KB |
answer = YES |
62 |
Correct |
128 ms |
9504 KB |
answer = NO |
63 |
Correct |
163 ms |
10340 KB |
answer = YES |
64 |
Correct |
145 ms |
10308 KB |
answer = NO |
65 |
Correct |
151 ms |
10316 KB |
answer = YES |
66 |
Correct |
4 ms |
2772 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
answer = YES |
2 |
Correct |
2 ms |
2644 KB |
answer = YES |
3 |
Correct |
2 ms |
2644 KB |
answer = YES |
4 |
Correct |
2 ms |
2656 KB |
answer = NO |
5 |
Correct |
2 ms |
2656 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
2 ms |
2644 KB |
answer = YES |
9 |
Correct |
2 ms |
2664 KB |
answer = NO |
10 |
Correct |
2 ms |
2644 KB |
answer = YES |
11 |
Correct |
2 ms |
2644 KB |
answer = YES |
12 |
Correct |
2 ms |
2644 KB |
answer = NO |
13 |
Correct |
2 ms |
2656 KB |
answer = YES |
14 |
Correct |
1 ms |
2660 KB |
answer = YES |
15 |
Correct |
2 ms |
2644 KB |
answer = YES |
16 |
Correct |
2 ms |
2644 KB |
answer = YES |
17 |
Correct |
2 ms |
2656 KB |
answer = YES |
18 |
Correct |
2 ms |
2660 KB |
answer = YES |
19 |
Correct |
2 ms |
2644 KB |
answer = YES |
20 |
Correct |
2 ms |
2644 KB |
answer = YES |
21 |
Correct |
2 ms |
2644 KB |
answer = YES |
22 |
Correct |
2 ms |
2644 KB |
answer = NO |
23 |
Correct |
2 ms |
2644 KB |
answer = NO |
24 |
Correct |
2 ms |
2644 KB |
answer = YES |
25 |
Correct |
2 ms |
2644 KB |
answer = YES |
26 |
Correct |
2 ms |
2676 KB |
answer = YES |
27 |
Correct |
2 ms |
2644 KB |
answer = YES |
28 |
Correct |
2 ms |
2644 KB |
answer = YES |
29 |
Correct |
2 ms |
2660 KB |
answer = YES |
30 |
Correct |
2 ms |
2644 KB |
answer = NO |
31 |
Correct |
2 ms |
2644 KB |
answer = YES |
32 |
Correct |
2 ms |
2644 KB |
answer = YES |
33 |
Correct |
2 ms |
2644 KB |
answer = YES |
34 |
Correct |
2 ms |
2644 KB |
answer = YES |
35 |
Correct |
2 ms |
2644 KB |
answer = YES |
36 |
Correct |
2 ms |
2644 KB |
answer = YES |
37 |
Correct |
2 ms |
2644 KB |
answer = YES |
38 |
Correct |
2 ms |
2660 KB |
answer = YES |
39 |
Correct |
2 ms |
2644 KB |
answer = YES |
40 |
Correct |
3 ms |
2644 KB |
answer = YES |
41 |
Correct |
3 ms |
2644 KB |
answer = NO |
42 |
Correct |
2 ms |
2668 KB |
answer = YES |
43 |
Correct |
3 ms |
2644 KB |
answer = YES |
44 |
Correct |
3 ms |
2644 KB |
answer = YES |
45 |
Correct |
4 ms |
2668 KB |
answer = YES |
46 |
Correct |
2 ms |
2644 KB |
answer = YES |
47 |
Correct |
3 ms |
2644 KB |
answer = YES |
48 |
Correct |
2 ms |
2644 KB |
answer = YES |
49 |
Correct |
13 ms |
3600 KB |
answer = YES |
50 |
Correct |
17 ms |
3824 KB |
answer = YES |
51 |
Correct |
14 ms |
3936 KB |
answer = YES |
52 |
Correct |
11 ms |
3696 KB |
answer = NO |
53 |
Correct |
4 ms |
2644 KB |
answer = YES |
54 |
Correct |
4 ms |
2848 KB |
answer = YES |
55 |
Correct |
8 ms |
3156 KB |
answer = YES |
56 |
Correct |
14 ms |
3568 KB |
answer = YES |
57 |
Correct |
14 ms |
3540 KB |
answer = YES |
58 |
Correct |
13 ms |
3436 KB |
answer = YES |
59 |
Correct |
14 ms |
3412 KB |
answer = YES |
60 |
Correct |
14 ms |
3436 KB |
answer = YES |
61 |
Correct |
10 ms |
3100 KB |
answer = YES |
62 |
Correct |
128 ms |
9504 KB |
answer = NO |
63 |
Correct |
163 ms |
10340 KB |
answer = YES |
64 |
Correct |
145 ms |
10308 KB |
answer = NO |
65 |
Correct |
151 ms |
10316 KB |
answer = YES |
66 |
Correct |
4 ms |
2772 KB |
answer = YES |
67 |
Correct |
125 ms |
16592 KB |
answer = YES |
68 |
Correct |
123 ms |
16548 KB |
answer = YES |
69 |
Correct |
146 ms |
16540 KB |
answer = YES |
70 |
Correct |
192 ms |
20932 KB |
answer = YES |
71 |
Correct |
127 ms |
16764 KB |
answer = YES |
72 |
Correct |
127 ms |
10892 KB |
answer = YES |
73 |
Correct |
125 ms |
10828 KB |
answer = YES |
74 |
Correct |
90 ms |
10984 KB |
answer = YES |
75 |
Correct |
61 ms |
10208 KB |
answer = NO |
76 |
Correct |
16 ms |
3760 KB |
answer = YES |
77 |
Correct |
31 ms |
4776 KB |
answer = YES |
78 |
Correct |
58 ms |
6268 KB |
answer = YES |
79 |
Correct |
127 ms |
9812 KB |
answer = YES |
80 |
Correct |
89 ms |
10936 KB |
answer = YES |
81 |
Correct |
93 ms |
15164 KB |
answer = NO |
82 |
Correct |
138 ms |
13772 KB |
answer = YES |
83 |
Correct |
151 ms |
16672 KB |
answer = YES |
84 |
Correct |
171 ms |
16584 KB |
answer = YES |
85 |
Correct |
122 ms |
16596 KB |
answer = YES |
86 |
Correct |
124 ms |
16588 KB |
answer = YES |
87 |
Correct |
113 ms |
11584 KB |
answer = NO |
88 |
Correct |
149 ms |
12900 KB |
answer = YES |
89 |
Correct |
143 ms |
9864 KB |
answer = YES |
90 |
Correct |
130 ms |
9856 KB |
answer = YES |
91 |
Correct |
153 ms |
9816 KB |
answer = YES |
92 |
Correct |
89 ms |
6856 KB |
answer = YES |
93 |
Correct |
62 ms |
6756 KB |
answer = YES |
94 |
Correct |
124 ms |
15548 KB |
answer = NO |
95 |
Correct |
105 ms |
9556 KB |
answer = NO |
96 |
Correct |
251 ms |
18648 KB |
answer = YES |
97 |
Correct |
95 ms |
15528 KB |
answer = NO |