# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
945465 |
2024-03-13T20:39:59 Z |
LucaIlie |
Graph (BOI20_graph) |
C++17 |
|
202 ms |
23496 KB |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int u, v, c;
int other( int x ) {
return u ^ v ^ x;
}
};
const int MAX_N = 1e5;
const int MAX_M = 2e5;
bool vis[MAX_N + 1];
int a[MAX_N + 1], b[MAX_N + 1];
double val[MAX_N + 1];
edge edges[MAX_M];
vector<int> adj[MAX_N + 1];
bool sePoate;
bool fixedX;
double x;
vector<int> vert;
void dfs( int u ) {
vert.push_back( u );
vis[u] = true;
for ( int e: adj[u] ) {
int v = edges[e].other( u ), c = edges[e].c;
if ( !vis[v] ) {
a[v] = -a[u];
b[v] = c - b[u];
dfs( v );
} else {
if ( a[u] + a[v] == 0 ) {
if ( b[u] + b[v] != c )
sePoate = false;
} else {
double xx = ((double)c - b[u] - b[v]) / (a[u] + a[v]);
if ( fixedX && x != xx )
sePoate = false;
else {
fixedX = true;
x = xx;
}
}
}
}
}
int main() {
int n, m;
cin >> n >> m;
for ( int i = 0; i < m; i++ ) {
cin >> edges[i].u >> edges[i].v >> edges[i].c;
adj[edges[i].u].push_back( i );
adj[edges[i].v].push_back( i );
}
for ( int v = 1; v <= n; v++ ) {
if ( vis[v] )
continue;
a[v] = 1;
b[v] = 0;
sePoate = true;
fixedX = false;
vert.clear();
dfs( v );
if ( !sePoate ) {
cout << "NO\n";
return 0;
}
//for ( int u: vert )
//cout << u << " " << a[u] << " " << b[u] << "\n";
if ( !fixedX ) {
map<int, vector<int>> events;
int sa = 0, sb = 0;
for ( int u: vert ) {
sa--;
if ( a[u] == 1 )
sb -= b[u];
else
sb += b[u];
events[(-b[u] / a[u])].push_back( u );
//cout << (-b[u] / a[u]) << "\n";
}
int minS = 1e9;
for ( auto p: events ) {
for ( int u: p.second ) {
if ( a[u] == 1 ) {
sa += 2;
sb += b[u] * 2;
} else {
sa += 2;
sb -= b[u] * 2;
}
}
int xx = (sa >= 0 ? p.first : events.upper_bound( p.first )->first);
if ( sa * xx + sb < minS ) {
minS = sa * xx + sb;
x = xx;
}
//cout << xx << " " << sa << " " << sb << " " << sa * xx + sb << "\n";
}
}
for ( int u: vert )
val[u] = x * a[u] + b[u];
}
cout << "YES\n";
for ( int v = 1; v <= n; v++ )
cout << val[v] << " ";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4700 KB |
answer = YES |
2 |
Correct |
1 ms |
4700 KB |
answer = YES |
3 |
Correct |
2 ms |
4696 KB |
answer = YES |
4 |
Correct |
1 ms |
4700 KB |
answer = NO |
5 |
Correct |
2 ms |
4700 KB |
answer = YES |
6 |
Correct |
1 ms |
4700 KB |
answer = YES |
7 |
Correct |
1 ms |
4700 KB |
answer = YES |
8 |
Correct |
2 ms |
4700 KB |
answer = YES |
9 |
Correct |
2 ms |
4696 KB |
answer = NO |
10 |
Correct |
1 ms |
4700 KB |
answer = YES |
11 |
Correct |
1 ms |
4700 KB |
answer = YES |
12 |
Correct |
1 ms |
4700 KB |
answer = NO |
13 |
Correct |
1 ms |
4700 KB |
answer = YES |
14 |
Correct |
2 ms |
4696 KB |
answer = YES |
15 |
Correct |
1 ms |
4700 KB |
answer = YES |
16 |
Correct |
2 ms |
4700 KB |
answer = YES |
17 |
Correct |
1 ms |
4696 KB |
answer = YES |
18 |
Correct |
1 ms |
4696 KB |
answer = YES |
19 |
Correct |
2 ms |
4700 KB |
answer = YES |
20 |
Correct |
1 ms |
4700 KB |
answer = YES |
21 |
Correct |
1 ms |
4700 KB |
answer = YES |
22 |
Correct |
1 ms |
4696 KB |
answer = NO |
23 |
Correct |
1 ms |
4696 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4700 KB |
answer = YES |
2 |
Correct |
1 ms |
4700 KB |
answer = YES |
3 |
Correct |
2 ms |
4696 KB |
answer = YES |
4 |
Correct |
1 ms |
4700 KB |
answer = NO |
5 |
Correct |
2 ms |
4700 KB |
answer = YES |
6 |
Correct |
1 ms |
4700 KB |
answer = YES |
7 |
Correct |
1 ms |
4700 KB |
answer = YES |
8 |
Correct |
2 ms |
4700 KB |
answer = YES |
9 |
Correct |
2 ms |
4696 KB |
answer = NO |
10 |
Correct |
1 ms |
4700 KB |
answer = YES |
11 |
Correct |
1 ms |
4700 KB |
answer = YES |
12 |
Correct |
1 ms |
4700 KB |
answer = NO |
13 |
Correct |
1 ms |
4700 KB |
answer = YES |
14 |
Correct |
2 ms |
4696 KB |
answer = YES |
15 |
Correct |
1 ms |
4700 KB |
answer = YES |
16 |
Correct |
2 ms |
4700 KB |
answer = YES |
17 |
Correct |
1 ms |
4696 KB |
answer = YES |
18 |
Correct |
1 ms |
4696 KB |
answer = YES |
19 |
Correct |
2 ms |
4700 KB |
answer = YES |
20 |
Correct |
1 ms |
4700 KB |
answer = YES |
21 |
Correct |
1 ms |
4700 KB |
answer = YES |
22 |
Correct |
1 ms |
4696 KB |
answer = NO |
23 |
Correct |
1 ms |
4696 KB |
answer = NO |
24 |
Correct |
2 ms |
4696 KB |
answer = YES |
25 |
Correct |
2 ms |
4952 KB |
answer = YES |
26 |
Correct |
1 ms |
4696 KB |
answer = YES |
27 |
Correct |
1 ms |
4696 KB |
answer = YES |
28 |
Correct |
1 ms |
4700 KB |
answer = YES |
29 |
Correct |
2 ms |
4700 KB |
answer = YES |
30 |
Correct |
1 ms |
4700 KB |
answer = NO |
31 |
Correct |
1 ms |
4700 KB |
answer = YES |
32 |
Correct |
2 ms |
4700 KB |
answer = YES |
33 |
Correct |
1 ms |
4700 KB |
answer = YES |
34 |
Correct |
2 ms |
4700 KB |
answer = YES |
35 |
Correct |
2 ms |
4700 KB |
answer = YES |
36 |
Correct |
1 ms |
4700 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4700 KB |
answer = YES |
2 |
Correct |
1 ms |
4700 KB |
answer = YES |
3 |
Correct |
2 ms |
4696 KB |
answer = YES |
4 |
Correct |
1 ms |
4700 KB |
answer = NO |
5 |
Correct |
2 ms |
4700 KB |
answer = YES |
6 |
Correct |
1 ms |
4700 KB |
answer = YES |
7 |
Correct |
1 ms |
4700 KB |
answer = YES |
8 |
Correct |
2 ms |
4700 KB |
answer = YES |
9 |
Correct |
2 ms |
4696 KB |
answer = NO |
10 |
Correct |
1 ms |
4700 KB |
answer = YES |
11 |
Correct |
1 ms |
4700 KB |
answer = YES |
12 |
Correct |
1 ms |
4700 KB |
answer = NO |
13 |
Correct |
1 ms |
4700 KB |
answer = YES |
14 |
Correct |
2 ms |
4696 KB |
answer = YES |
15 |
Correct |
1 ms |
4700 KB |
answer = YES |
16 |
Correct |
2 ms |
4700 KB |
answer = YES |
17 |
Correct |
1 ms |
4696 KB |
answer = YES |
18 |
Correct |
1 ms |
4696 KB |
answer = YES |
19 |
Correct |
2 ms |
4700 KB |
answer = YES |
20 |
Correct |
1 ms |
4700 KB |
answer = YES |
21 |
Correct |
1 ms |
4700 KB |
answer = YES |
22 |
Correct |
1 ms |
4696 KB |
answer = NO |
23 |
Correct |
1 ms |
4696 KB |
answer = NO |
24 |
Correct |
2 ms |
4696 KB |
answer = YES |
25 |
Correct |
2 ms |
4952 KB |
answer = YES |
26 |
Correct |
1 ms |
4696 KB |
answer = YES |
27 |
Correct |
1 ms |
4696 KB |
answer = YES |
28 |
Correct |
1 ms |
4700 KB |
answer = YES |
29 |
Correct |
2 ms |
4700 KB |
answer = YES |
30 |
Correct |
1 ms |
4700 KB |
answer = NO |
31 |
Correct |
1 ms |
4700 KB |
answer = YES |
32 |
Correct |
2 ms |
4700 KB |
answer = YES |
33 |
Correct |
1 ms |
4700 KB |
answer = YES |
34 |
Correct |
2 ms |
4700 KB |
answer = YES |
35 |
Correct |
2 ms |
4700 KB |
answer = YES |
36 |
Correct |
1 ms |
4700 KB |
answer = YES |
37 |
Correct |
1 ms |
4700 KB |
answer = YES |
38 |
Correct |
1 ms |
4700 KB |
answer = YES |
39 |
Correct |
2 ms |
4700 KB |
answer = YES |
40 |
Correct |
2 ms |
4696 KB |
answer = YES |
41 |
Correct |
2 ms |
4700 KB |
answer = NO |
42 |
Correct |
3 ms |
4700 KB |
answer = YES |
43 |
Correct |
2 ms |
4700 KB |
answer = YES |
44 |
Correct |
2 ms |
4700 KB |
answer = YES |
45 |
Correct |
2 ms |
4700 KB |
answer = YES |
46 |
Correct |
1 ms |
4700 KB |
answer = YES |
47 |
Correct |
2 ms |
4700 KB |
answer = YES |
48 |
Correct |
2 ms |
4856 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4700 KB |
answer = YES |
2 |
Correct |
1 ms |
4700 KB |
answer = YES |
3 |
Correct |
2 ms |
4696 KB |
answer = YES |
4 |
Correct |
1 ms |
4700 KB |
answer = NO |
5 |
Correct |
2 ms |
4700 KB |
answer = YES |
6 |
Correct |
1 ms |
4700 KB |
answer = YES |
7 |
Correct |
1 ms |
4700 KB |
answer = YES |
8 |
Correct |
2 ms |
4700 KB |
answer = YES |
9 |
Correct |
2 ms |
4696 KB |
answer = NO |
10 |
Correct |
1 ms |
4700 KB |
answer = YES |
11 |
Correct |
1 ms |
4700 KB |
answer = YES |
12 |
Correct |
1 ms |
4700 KB |
answer = NO |
13 |
Correct |
1 ms |
4700 KB |
answer = YES |
14 |
Correct |
2 ms |
4696 KB |
answer = YES |
15 |
Correct |
1 ms |
4700 KB |
answer = YES |
16 |
Correct |
2 ms |
4700 KB |
answer = YES |
17 |
Correct |
1 ms |
4696 KB |
answer = YES |
18 |
Correct |
1 ms |
4696 KB |
answer = YES |
19 |
Correct |
2 ms |
4700 KB |
answer = YES |
20 |
Correct |
1 ms |
4700 KB |
answer = YES |
21 |
Correct |
1 ms |
4700 KB |
answer = YES |
22 |
Correct |
1 ms |
4696 KB |
answer = NO |
23 |
Correct |
1 ms |
4696 KB |
answer = NO |
24 |
Correct |
2 ms |
4696 KB |
answer = YES |
25 |
Correct |
2 ms |
4952 KB |
answer = YES |
26 |
Correct |
1 ms |
4696 KB |
answer = YES |
27 |
Correct |
1 ms |
4696 KB |
answer = YES |
28 |
Correct |
1 ms |
4700 KB |
answer = YES |
29 |
Correct |
2 ms |
4700 KB |
answer = YES |
30 |
Correct |
1 ms |
4700 KB |
answer = NO |
31 |
Correct |
1 ms |
4700 KB |
answer = YES |
32 |
Correct |
2 ms |
4700 KB |
answer = YES |
33 |
Correct |
1 ms |
4700 KB |
answer = YES |
34 |
Correct |
2 ms |
4700 KB |
answer = YES |
35 |
Correct |
2 ms |
4700 KB |
answer = YES |
36 |
Correct |
1 ms |
4700 KB |
answer = YES |
37 |
Correct |
1 ms |
4700 KB |
answer = YES |
38 |
Correct |
1 ms |
4700 KB |
answer = YES |
39 |
Correct |
2 ms |
4700 KB |
answer = YES |
40 |
Correct |
2 ms |
4696 KB |
answer = YES |
41 |
Correct |
2 ms |
4700 KB |
answer = NO |
42 |
Correct |
3 ms |
4700 KB |
answer = YES |
43 |
Correct |
2 ms |
4700 KB |
answer = YES |
44 |
Correct |
2 ms |
4700 KB |
answer = YES |
45 |
Correct |
2 ms |
4700 KB |
answer = YES |
46 |
Correct |
1 ms |
4700 KB |
answer = YES |
47 |
Correct |
2 ms |
4700 KB |
answer = YES |
48 |
Correct |
2 ms |
4856 KB |
answer = YES |
49 |
Correct |
10 ms |
5468 KB |
answer = YES |
50 |
Correct |
11 ms |
5724 KB |
answer = YES |
51 |
Correct |
11 ms |
5924 KB |
answer = YES |
52 |
Correct |
7 ms |
5724 KB |
answer = NO |
53 |
Correct |
3 ms |
4700 KB |
answer = YES |
54 |
Correct |
3 ms |
4700 KB |
answer = YES |
55 |
Correct |
6 ms |
4956 KB |
answer = YES |
56 |
Correct |
10 ms |
5468 KB |
answer = YES |
57 |
Correct |
10 ms |
5212 KB |
answer = YES |
58 |
Correct |
12 ms |
5212 KB |
answer = YES |
59 |
Correct |
10 ms |
5212 KB |
answer = YES |
60 |
Correct |
10 ms |
5212 KB |
answer = YES |
61 |
Correct |
6 ms |
4956 KB |
answer = YES |
62 |
Correct |
104 ms |
11860 KB |
answer = NO |
63 |
Correct |
107 ms |
12084 KB |
answer = YES |
64 |
Correct |
112 ms |
12192 KB |
answer = NO |
65 |
Correct |
113 ms |
12116 KB |
answer = YES |
66 |
Correct |
3 ms |
4696 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4700 KB |
answer = YES |
2 |
Correct |
1 ms |
4700 KB |
answer = YES |
3 |
Correct |
2 ms |
4696 KB |
answer = YES |
4 |
Correct |
1 ms |
4700 KB |
answer = NO |
5 |
Correct |
2 ms |
4700 KB |
answer = YES |
6 |
Correct |
1 ms |
4700 KB |
answer = YES |
7 |
Correct |
1 ms |
4700 KB |
answer = YES |
8 |
Correct |
2 ms |
4700 KB |
answer = YES |
9 |
Correct |
2 ms |
4696 KB |
answer = NO |
10 |
Correct |
1 ms |
4700 KB |
answer = YES |
11 |
Correct |
1 ms |
4700 KB |
answer = YES |
12 |
Correct |
1 ms |
4700 KB |
answer = NO |
13 |
Correct |
1 ms |
4700 KB |
answer = YES |
14 |
Correct |
2 ms |
4696 KB |
answer = YES |
15 |
Correct |
1 ms |
4700 KB |
answer = YES |
16 |
Correct |
2 ms |
4700 KB |
answer = YES |
17 |
Correct |
1 ms |
4696 KB |
answer = YES |
18 |
Correct |
1 ms |
4696 KB |
answer = YES |
19 |
Correct |
2 ms |
4700 KB |
answer = YES |
20 |
Correct |
1 ms |
4700 KB |
answer = YES |
21 |
Correct |
1 ms |
4700 KB |
answer = YES |
22 |
Correct |
1 ms |
4696 KB |
answer = NO |
23 |
Correct |
1 ms |
4696 KB |
answer = NO |
24 |
Correct |
2 ms |
4696 KB |
answer = YES |
25 |
Correct |
2 ms |
4952 KB |
answer = YES |
26 |
Correct |
1 ms |
4696 KB |
answer = YES |
27 |
Correct |
1 ms |
4696 KB |
answer = YES |
28 |
Correct |
1 ms |
4700 KB |
answer = YES |
29 |
Correct |
2 ms |
4700 KB |
answer = YES |
30 |
Correct |
1 ms |
4700 KB |
answer = NO |
31 |
Correct |
1 ms |
4700 KB |
answer = YES |
32 |
Correct |
2 ms |
4700 KB |
answer = YES |
33 |
Correct |
1 ms |
4700 KB |
answer = YES |
34 |
Correct |
2 ms |
4700 KB |
answer = YES |
35 |
Correct |
2 ms |
4700 KB |
answer = YES |
36 |
Correct |
1 ms |
4700 KB |
answer = YES |
37 |
Correct |
1 ms |
4700 KB |
answer = YES |
38 |
Correct |
1 ms |
4700 KB |
answer = YES |
39 |
Correct |
2 ms |
4700 KB |
answer = YES |
40 |
Correct |
2 ms |
4696 KB |
answer = YES |
41 |
Correct |
2 ms |
4700 KB |
answer = NO |
42 |
Correct |
3 ms |
4700 KB |
answer = YES |
43 |
Correct |
2 ms |
4700 KB |
answer = YES |
44 |
Correct |
2 ms |
4700 KB |
answer = YES |
45 |
Correct |
2 ms |
4700 KB |
answer = YES |
46 |
Correct |
1 ms |
4700 KB |
answer = YES |
47 |
Correct |
2 ms |
4700 KB |
answer = YES |
48 |
Correct |
2 ms |
4856 KB |
answer = YES |
49 |
Correct |
10 ms |
5468 KB |
answer = YES |
50 |
Correct |
11 ms |
5724 KB |
answer = YES |
51 |
Correct |
11 ms |
5924 KB |
answer = YES |
52 |
Correct |
7 ms |
5724 KB |
answer = NO |
53 |
Correct |
3 ms |
4700 KB |
answer = YES |
54 |
Correct |
3 ms |
4700 KB |
answer = YES |
55 |
Correct |
6 ms |
4956 KB |
answer = YES |
56 |
Correct |
10 ms |
5468 KB |
answer = YES |
57 |
Correct |
10 ms |
5212 KB |
answer = YES |
58 |
Correct |
12 ms |
5212 KB |
answer = YES |
59 |
Correct |
10 ms |
5212 KB |
answer = YES |
60 |
Correct |
10 ms |
5212 KB |
answer = YES |
61 |
Correct |
6 ms |
4956 KB |
answer = YES |
62 |
Correct |
104 ms |
11860 KB |
answer = NO |
63 |
Correct |
107 ms |
12084 KB |
answer = YES |
64 |
Correct |
112 ms |
12192 KB |
answer = NO |
65 |
Correct |
113 ms |
12116 KB |
answer = YES |
66 |
Correct |
3 ms |
4696 KB |
answer = YES |
67 |
Correct |
102 ms |
19656 KB |
answer = YES |
68 |
Correct |
107 ms |
19352 KB |
answer = YES |
69 |
Correct |
99 ms |
19152 KB |
answer = YES |
70 |
Correct |
158 ms |
23496 KB |
answer = YES |
71 |
Correct |
101 ms |
19412 KB |
answer = YES |
72 |
Correct |
103 ms |
11768 KB |
answer = YES |
73 |
Correct |
101 ms |
11476 KB |
answer = YES |
74 |
Correct |
80 ms |
13124 KB |
answer = YES |
75 |
Correct |
44 ms |
12504 KB |
answer = NO |
76 |
Correct |
12 ms |
5464 KB |
answer = YES |
77 |
Correct |
25 ms |
6464 KB |
answer = YES |
78 |
Correct |
43 ms |
7728 KB |
answer = YES |
79 |
Correct |
86 ms |
10568 KB |
answer = YES |
80 |
Correct |
71 ms |
13572 KB |
answer = YES |
81 |
Correct |
67 ms |
14544 KB |
answer = NO |
82 |
Correct |
104 ms |
18888 KB |
answer = YES |
83 |
Correct |
114 ms |
19408 KB |
answer = YES |
84 |
Correct |
115 ms |
20176 KB |
answer = YES |
85 |
Correct |
120 ms |
19580 KB |
answer = YES |
86 |
Correct |
100 ms |
19316 KB |
answer = YES |
87 |
Correct |
66 ms |
13264 KB |
answer = NO |
88 |
Correct |
111 ms |
14684 KB |
answer = YES |
89 |
Correct |
108 ms |
11344 KB |
answer = YES |
90 |
Correct |
96 ms |
11092 KB |
answer = YES |
91 |
Correct |
100 ms |
11148 KB |
answer = YES |
92 |
Correct |
63 ms |
8344 KB |
answer = YES |
93 |
Correct |
55 ms |
8144 KB |
answer = YES |
94 |
Correct |
76 ms |
18388 KB |
answer = NO |
95 |
Correct |
61 ms |
10832 KB |
answer = NO |
96 |
Correct |
202 ms |
19160 KB |
answer = YES |
97 |
Correct |
67 ms |
18388 KB |
answer = NO |