# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1013118 |
2024-07-03T08:08:52 Z |
LucaIlie |
Graph (BOI20_graph) |
C++17 |
|
198 ms |
40872 KB |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define nmax 100001
vector <int> edges[nmax], price[nmax], arbore[nmax], pricearb[nmax], v;
int daddy[nmax], type[nmax], paritate[nmax], comp[nmax], muchii[nmax], numodific[nmax];
double modificat[nmax];
const int inf = 1e8;
int find_daddy( int a ) {
int x;
if( daddy[a] == a )
return a;
x = find_daddy(daddy[a]);
daddy[a] = x;
return x;
}
void marry_daddy( int a, int b ) {
int x, y;
x = find_daddy( a );
y = find_daddy( b );
daddy[x] = y;
}
void dfs( int vf, int parent ) {
int i, fiu;
v.push_back(type[vf] * paritate[vf]);
comp[find_daddy(vf)]++;
muchii[find_daddy(vf)] += edges[vf].size();
//cout << vf << "\n";
for( i = 0; i < arbore[vf].size(); i++ ) {
fiu = arbore[vf][i];
if( fiu == parent )
continue;
type[fiu] = pricearb[vf][i] - type[vf];
paritate[fiu] = -paritate[vf];
//cout << fiu << " " << type[fiu] << " " << pricearb[vf][i] << " " << type[vf] << "\n";
dfs( fiu, vf );
}
}
void afisare( int x ) {
if( (x + inf) % 2 == 0 )
cout << x / 2 << " ";
else
cout << (x - 1) / 2 << ".5 ";
}
int main() {
int n, m, i, a, b, c, j;
bool ok = true;
cin >> n >> m;
for( i = 1; i <= n; i++ )
daddy[i] = i;
for( i = 0; i < m; i++ ) {
cin >> a >> b >> c;
edges[a].push_back( b );
edges[b].push_back( a );
price[a].push_back( c );
price[b].push_back( c );
if( find_daddy(a) != find_daddy(b) ) {
marry_daddy( a, b );
arbore[a].push_back(b);
arbore[b].push_back(a);
pricearb[a].push_back(c);
pricearb[b].push_back(c);
}
}
for( i = 1; i <= n; i++ ) {
if( find_daddy(i) == i ) {
paritate[i] = 1;
dfs( i, 0 );
if( 2 * comp[i] == muchii[i] + 2 ) {
//cout << ".";
sort(v.begin(), v.end());
//for( j = 0; j < v.size(); j++ )
// cout << v[j] << " ";
//cout << "\n";
modificat[find_daddy(i)] = -v[(v.size())/ 2];
}
v.clear();
}
}
//for( i = 1; i <= n; i++ )
// cout << type[i] << " ";
for( i = 1; i <= n; i++ ) {
for( j = 0; j < edges[i].size(); j++ ) {
if( type[i] + type[edges[i][j]] + (paritate[i] + paritate[edges[i][j]]) * modificat[find_daddy(i)] != price[i][j] ) {
if( modificat[find_daddy(i)] == 0 && paritate[i] == paritate[edges[i][j]] )
modificat[find_daddy(i)] = (((double)price[i][j] - type[i] - type[edges[i][j]]) / 2) * paritate[i];
else ok = false;
} else if( paritate[i] == paritate[edges[i][j]] )
numodific[find_daddy(i)] = 1;
}
}
for( i = 1; i <= n; i++ ) {
if( find_daddy(i) == i && modificat[i] == 0 && numodific[i] == 0 ) {
paritate[i] = 1;
dfs( i, 0 );
//cout << ".";
sort(v.begin(), v.end());
//for( j = 0; j < v.size(); j++ )
// cout << v[j] << " ";
//cout << "\n";
modificat[find_daddy(i)] = -v[(v.size())/ 2];
v.clear();
}
}
//cout << "\n";
//for( i = 1; i <= n; i++ )
// cout << type[i] + paritate[i] * modificat[find_daddy(i)] << " ";
if( !ok ) {
cout << "NO\n";
return 0;
}
cout << "YES\n";
for( i = 1; i <= n; i++ )
cout << type[i] + paritate[i] * modificat[find_daddy(i)] << " ";
return 0;
}
Compilation message
Graph.cpp: In function 'void dfs(int, int)':
Graph.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for( i = 0; i < arbore[vf].size(); i++ ) {
| ~~^~~~~~~~~~~~~~~~~~~
Graph.cpp: In function 'int main()':
Graph.cpp:92:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | for( j = 0; j < edges[i].size(); j++ ) {
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
answer = YES |
2 |
Correct |
2 ms |
12636 KB |
answer = YES |
3 |
Correct |
2 ms |
12636 KB |
answer = YES |
4 |
Correct |
2 ms |
12632 KB |
answer = NO |
5 |
Correct |
2 ms |
12636 KB |
answer = YES |
6 |
Correct |
2 ms |
12636 KB |
answer = YES |
7 |
Correct |
2 ms |
12636 KB |
answer = YES |
8 |
Correct |
2 ms |
12636 KB |
answer = YES |
9 |
Correct |
2 ms |
12788 KB |
answer = NO |
10 |
Correct |
2 ms |
12636 KB |
answer = YES |
11 |
Correct |
2 ms |
12636 KB |
answer = YES |
12 |
Correct |
2 ms |
12632 KB |
answer = NO |
13 |
Correct |
2 ms |
12632 KB |
answer = YES |
14 |
Correct |
2 ms |
12632 KB |
answer = YES |
15 |
Correct |
2 ms |
12636 KB |
answer = YES |
16 |
Correct |
2 ms |
12636 KB |
answer = YES |
17 |
Correct |
2 ms |
12632 KB |
answer = YES |
18 |
Correct |
2 ms |
12632 KB |
answer = YES |
19 |
Correct |
2 ms |
12636 KB |
answer = YES |
20 |
Correct |
2 ms |
12636 KB |
answer = YES |
21 |
Correct |
2 ms |
12636 KB |
answer = YES |
22 |
Correct |
2 ms |
12636 KB |
answer = NO |
23 |
Correct |
2 ms |
12636 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
answer = YES |
2 |
Correct |
2 ms |
12636 KB |
answer = YES |
3 |
Correct |
2 ms |
12636 KB |
answer = YES |
4 |
Correct |
2 ms |
12632 KB |
answer = NO |
5 |
Correct |
2 ms |
12636 KB |
answer = YES |
6 |
Correct |
2 ms |
12636 KB |
answer = YES |
7 |
Correct |
2 ms |
12636 KB |
answer = YES |
8 |
Correct |
2 ms |
12636 KB |
answer = YES |
9 |
Correct |
2 ms |
12788 KB |
answer = NO |
10 |
Correct |
2 ms |
12636 KB |
answer = YES |
11 |
Correct |
2 ms |
12636 KB |
answer = YES |
12 |
Correct |
2 ms |
12632 KB |
answer = NO |
13 |
Correct |
2 ms |
12632 KB |
answer = YES |
14 |
Correct |
2 ms |
12632 KB |
answer = YES |
15 |
Correct |
2 ms |
12636 KB |
answer = YES |
16 |
Correct |
2 ms |
12636 KB |
answer = YES |
17 |
Correct |
2 ms |
12632 KB |
answer = YES |
18 |
Correct |
2 ms |
12632 KB |
answer = YES |
19 |
Correct |
2 ms |
12636 KB |
answer = YES |
20 |
Correct |
2 ms |
12636 KB |
answer = YES |
21 |
Correct |
2 ms |
12636 KB |
answer = YES |
22 |
Correct |
2 ms |
12636 KB |
answer = NO |
23 |
Correct |
2 ms |
12636 KB |
answer = NO |
24 |
Correct |
2 ms |
12636 KB |
answer = YES |
25 |
Correct |
2 ms |
12636 KB |
answer = YES |
26 |
Correct |
2 ms |
12636 KB |
answer = YES |
27 |
Correct |
2 ms |
12636 KB |
answer = YES |
28 |
Correct |
2 ms |
12636 KB |
answer = YES |
29 |
Correct |
3 ms |
12636 KB |
answer = YES |
30 |
Correct |
2 ms |
12636 KB |
answer = NO |
31 |
Correct |
2 ms |
12636 KB |
answer = YES |
32 |
Correct |
2 ms |
12636 KB |
answer = YES |
33 |
Correct |
2 ms |
12636 KB |
answer = YES |
34 |
Correct |
2 ms |
12636 KB |
answer = YES |
35 |
Correct |
2 ms |
12636 KB |
answer = YES |
36 |
Correct |
2 ms |
12632 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
answer = YES |
2 |
Correct |
2 ms |
12636 KB |
answer = YES |
3 |
Correct |
2 ms |
12636 KB |
answer = YES |
4 |
Correct |
2 ms |
12632 KB |
answer = NO |
5 |
Correct |
2 ms |
12636 KB |
answer = YES |
6 |
Correct |
2 ms |
12636 KB |
answer = YES |
7 |
Correct |
2 ms |
12636 KB |
answer = YES |
8 |
Correct |
2 ms |
12636 KB |
answer = YES |
9 |
Correct |
2 ms |
12788 KB |
answer = NO |
10 |
Correct |
2 ms |
12636 KB |
answer = YES |
11 |
Correct |
2 ms |
12636 KB |
answer = YES |
12 |
Correct |
2 ms |
12632 KB |
answer = NO |
13 |
Correct |
2 ms |
12632 KB |
answer = YES |
14 |
Correct |
2 ms |
12632 KB |
answer = YES |
15 |
Correct |
2 ms |
12636 KB |
answer = YES |
16 |
Correct |
2 ms |
12636 KB |
answer = YES |
17 |
Correct |
2 ms |
12632 KB |
answer = YES |
18 |
Correct |
2 ms |
12632 KB |
answer = YES |
19 |
Correct |
2 ms |
12636 KB |
answer = YES |
20 |
Correct |
2 ms |
12636 KB |
answer = YES |
21 |
Correct |
2 ms |
12636 KB |
answer = YES |
22 |
Correct |
2 ms |
12636 KB |
answer = NO |
23 |
Correct |
2 ms |
12636 KB |
answer = NO |
24 |
Correct |
2 ms |
12636 KB |
answer = YES |
25 |
Correct |
2 ms |
12636 KB |
answer = YES |
26 |
Correct |
2 ms |
12636 KB |
answer = YES |
27 |
Correct |
2 ms |
12636 KB |
answer = YES |
28 |
Correct |
2 ms |
12636 KB |
answer = YES |
29 |
Correct |
3 ms |
12636 KB |
answer = YES |
30 |
Correct |
2 ms |
12636 KB |
answer = NO |
31 |
Correct |
2 ms |
12636 KB |
answer = YES |
32 |
Correct |
2 ms |
12636 KB |
answer = YES |
33 |
Correct |
2 ms |
12636 KB |
answer = YES |
34 |
Correct |
2 ms |
12636 KB |
answer = YES |
35 |
Correct |
2 ms |
12636 KB |
answer = YES |
36 |
Correct |
2 ms |
12632 KB |
answer = YES |
37 |
Correct |
2 ms |
12636 KB |
answer = YES |
38 |
Correct |
2 ms |
12636 KB |
answer = YES |
39 |
Correct |
3 ms |
12636 KB |
answer = YES |
40 |
Correct |
3 ms |
12892 KB |
answer = YES |
41 |
Correct |
2 ms |
12776 KB |
answer = NO |
42 |
Correct |
3 ms |
12960 KB |
answer = YES |
43 |
Correct |
3 ms |
12892 KB |
answer = YES |
44 |
Correct |
3 ms |
12892 KB |
answer = YES |
45 |
Correct |
3 ms |
12892 KB |
answer = YES |
46 |
Correct |
2 ms |
12636 KB |
answer = YES |
47 |
Correct |
3 ms |
12776 KB |
answer = YES |
48 |
Correct |
3 ms |
12892 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
answer = YES |
2 |
Correct |
2 ms |
12636 KB |
answer = YES |
3 |
Correct |
2 ms |
12636 KB |
answer = YES |
4 |
Correct |
2 ms |
12632 KB |
answer = NO |
5 |
Correct |
2 ms |
12636 KB |
answer = YES |
6 |
Correct |
2 ms |
12636 KB |
answer = YES |
7 |
Correct |
2 ms |
12636 KB |
answer = YES |
8 |
Correct |
2 ms |
12636 KB |
answer = YES |
9 |
Correct |
2 ms |
12788 KB |
answer = NO |
10 |
Correct |
2 ms |
12636 KB |
answer = YES |
11 |
Correct |
2 ms |
12636 KB |
answer = YES |
12 |
Correct |
2 ms |
12632 KB |
answer = NO |
13 |
Correct |
2 ms |
12632 KB |
answer = YES |
14 |
Correct |
2 ms |
12632 KB |
answer = YES |
15 |
Correct |
2 ms |
12636 KB |
answer = YES |
16 |
Correct |
2 ms |
12636 KB |
answer = YES |
17 |
Correct |
2 ms |
12632 KB |
answer = YES |
18 |
Correct |
2 ms |
12632 KB |
answer = YES |
19 |
Correct |
2 ms |
12636 KB |
answer = YES |
20 |
Correct |
2 ms |
12636 KB |
answer = YES |
21 |
Correct |
2 ms |
12636 KB |
answer = YES |
22 |
Correct |
2 ms |
12636 KB |
answer = NO |
23 |
Correct |
2 ms |
12636 KB |
answer = NO |
24 |
Correct |
2 ms |
12636 KB |
answer = YES |
25 |
Correct |
2 ms |
12636 KB |
answer = YES |
26 |
Correct |
2 ms |
12636 KB |
answer = YES |
27 |
Correct |
2 ms |
12636 KB |
answer = YES |
28 |
Correct |
2 ms |
12636 KB |
answer = YES |
29 |
Correct |
3 ms |
12636 KB |
answer = YES |
30 |
Correct |
2 ms |
12636 KB |
answer = NO |
31 |
Correct |
2 ms |
12636 KB |
answer = YES |
32 |
Correct |
2 ms |
12636 KB |
answer = YES |
33 |
Correct |
2 ms |
12636 KB |
answer = YES |
34 |
Correct |
2 ms |
12636 KB |
answer = YES |
35 |
Correct |
2 ms |
12636 KB |
answer = YES |
36 |
Correct |
2 ms |
12632 KB |
answer = YES |
37 |
Correct |
2 ms |
12636 KB |
answer = YES |
38 |
Correct |
2 ms |
12636 KB |
answer = YES |
39 |
Correct |
3 ms |
12636 KB |
answer = YES |
40 |
Correct |
3 ms |
12892 KB |
answer = YES |
41 |
Correct |
2 ms |
12776 KB |
answer = NO |
42 |
Correct |
3 ms |
12960 KB |
answer = YES |
43 |
Correct |
3 ms |
12892 KB |
answer = YES |
44 |
Correct |
3 ms |
12892 KB |
answer = YES |
45 |
Correct |
3 ms |
12892 KB |
answer = YES |
46 |
Correct |
2 ms |
12636 KB |
answer = YES |
47 |
Correct |
3 ms |
12776 KB |
answer = YES |
48 |
Correct |
3 ms |
12892 KB |
answer = YES |
49 |
Correct |
13 ms |
14172 KB |
answer = YES |
50 |
Correct |
13 ms |
14684 KB |
answer = YES |
51 |
Correct |
12 ms |
14744 KB |
answer = YES |
52 |
Correct |
10 ms |
14476 KB |
answer = NO |
53 |
Correct |
4 ms |
12892 KB |
answer = YES |
54 |
Correct |
4 ms |
13148 KB |
answer = YES |
55 |
Correct |
7 ms |
13568 KB |
answer = YES |
56 |
Correct |
15 ms |
14172 KB |
answer = YES |
57 |
Correct |
11 ms |
14072 KB |
answer = YES |
58 |
Correct |
11 ms |
13916 KB |
answer = YES |
59 |
Correct |
11 ms |
13916 KB |
answer = YES |
60 |
Correct |
12 ms |
14172 KB |
answer = YES |
61 |
Correct |
7 ms |
13400 KB |
answer = YES |
62 |
Correct |
91 ms |
20616 KB |
answer = NO |
63 |
Correct |
92 ms |
20508 KB |
answer = YES |
64 |
Correct |
122 ms |
20560 KB |
answer = NO |
65 |
Correct |
88 ms |
20560 KB |
answer = YES |
66 |
Correct |
4 ms |
12892 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
answer = YES |
2 |
Correct |
2 ms |
12636 KB |
answer = YES |
3 |
Correct |
2 ms |
12636 KB |
answer = YES |
4 |
Correct |
2 ms |
12632 KB |
answer = NO |
5 |
Correct |
2 ms |
12636 KB |
answer = YES |
6 |
Correct |
2 ms |
12636 KB |
answer = YES |
7 |
Correct |
2 ms |
12636 KB |
answer = YES |
8 |
Correct |
2 ms |
12636 KB |
answer = YES |
9 |
Correct |
2 ms |
12788 KB |
answer = NO |
10 |
Correct |
2 ms |
12636 KB |
answer = YES |
11 |
Correct |
2 ms |
12636 KB |
answer = YES |
12 |
Correct |
2 ms |
12632 KB |
answer = NO |
13 |
Correct |
2 ms |
12632 KB |
answer = YES |
14 |
Correct |
2 ms |
12632 KB |
answer = YES |
15 |
Correct |
2 ms |
12636 KB |
answer = YES |
16 |
Correct |
2 ms |
12636 KB |
answer = YES |
17 |
Correct |
2 ms |
12632 KB |
answer = YES |
18 |
Correct |
2 ms |
12632 KB |
answer = YES |
19 |
Correct |
2 ms |
12636 KB |
answer = YES |
20 |
Correct |
2 ms |
12636 KB |
answer = YES |
21 |
Correct |
2 ms |
12636 KB |
answer = YES |
22 |
Correct |
2 ms |
12636 KB |
answer = NO |
23 |
Correct |
2 ms |
12636 KB |
answer = NO |
24 |
Correct |
2 ms |
12636 KB |
answer = YES |
25 |
Correct |
2 ms |
12636 KB |
answer = YES |
26 |
Correct |
2 ms |
12636 KB |
answer = YES |
27 |
Correct |
2 ms |
12636 KB |
answer = YES |
28 |
Correct |
2 ms |
12636 KB |
answer = YES |
29 |
Correct |
3 ms |
12636 KB |
answer = YES |
30 |
Correct |
2 ms |
12636 KB |
answer = NO |
31 |
Correct |
2 ms |
12636 KB |
answer = YES |
32 |
Correct |
2 ms |
12636 KB |
answer = YES |
33 |
Correct |
2 ms |
12636 KB |
answer = YES |
34 |
Correct |
2 ms |
12636 KB |
answer = YES |
35 |
Correct |
2 ms |
12636 KB |
answer = YES |
36 |
Correct |
2 ms |
12632 KB |
answer = YES |
37 |
Correct |
2 ms |
12636 KB |
answer = YES |
38 |
Correct |
2 ms |
12636 KB |
answer = YES |
39 |
Correct |
3 ms |
12636 KB |
answer = YES |
40 |
Correct |
3 ms |
12892 KB |
answer = YES |
41 |
Correct |
2 ms |
12776 KB |
answer = NO |
42 |
Correct |
3 ms |
12960 KB |
answer = YES |
43 |
Correct |
3 ms |
12892 KB |
answer = YES |
44 |
Correct |
3 ms |
12892 KB |
answer = YES |
45 |
Correct |
3 ms |
12892 KB |
answer = YES |
46 |
Correct |
2 ms |
12636 KB |
answer = YES |
47 |
Correct |
3 ms |
12776 KB |
answer = YES |
48 |
Correct |
3 ms |
12892 KB |
answer = YES |
49 |
Correct |
13 ms |
14172 KB |
answer = YES |
50 |
Correct |
13 ms |
14684 KB |
answer = YES |
51 |
Correct |
12 ms |
14744 KB |
answer = YES |
52 |
Correct |
10 ms |
14476 KB |
answer = NO |
53 |
Correct |
4 ms |
12892 KB |
answer = YES |
54 |
Correct |
4 ms |
13148 KB |
answer = YES |
55 |
Correct |
7 ms |
13568 KB |
answer = YES |
56 |
Correct |
15 ms |
14172 KB |
answer = YES |
57 |
Correct |
11 ms |
14072 KB |
answer = YES |
58 |
Correct |
11 ms |
13916 KB |
answer = YES |
59 |
Correct |
11 ms |
13916 KB |
answer = YES |
60 |
Correct |
12 ms |
14172 KB |
answer = YES |
61 |
Correct |
7 ms |
13400 KB |
answer = YES |
62 |
Correct |
91 ms |
20616 KB |
answer = NO |
63 |
Correct |
92 ms |
20508 KB |
answer = YES |
64 |
Correct |
122 ms |
20560 KB |
answer = NO |
65 |
Correct |
88 ms |
20560 KB |
answer = YES |
66 |
Correct |
4 ms |
12892 KB |
answer = YES |
67 |
Correct |
98 ms |
36816 KB |
answer = YES |
68 |
Correct |
100 ms |
36564 KB |
answer = YES |
69 |
Correct |
98 ms |
34832 KB |
answer = YES |
70 |
Correct |
149 ms |
40872 KB |
answer = YES |
71 |
Correct |
99 ms |
35024 KB |
answer = YES |
72 |
Correct |
149 ms |
26056 KB |
answer = YES |
73 |
Correct |
131 ms |
26060 KB |
answer = YES |
74 |
Correct |
88 ms |
23500 KB |
answer = YES |
75 |
Correct |
63 ms |
23352 KB |
answer = NO |
76 |
Correct |
16 ms |
11608 KB |
answer = YES |
77 |
Correct |
34 ms |
13916 KB |
answer = YES |
78 |
Correct |
62 ms |
16848 KB |
answer = YES |
79 |
Correct |
117 ms |
23624 KB |
answer = YES |
80 |
Correct |
78 ms |
23372 KB |
answer = YES |
81 |
Correct |
96 ms |
34716 KB |
answer = NO |
82 |
Correct |
127 ms |
30800 KB |
answer = YES |
83 |
Correct |
181 ms |
35020 KB |
answer = YES |
84 |
Correct |
169 ms |
34968 KB |
answer = YES |
85 |
Correct |
106 ms |
35060 KB |
answer = YES |
86 |
Correct |
101 ms |
35056 KB |
answer = YES |
87 |
Correct |
111 ms |
28372 KB |
answer = NO |
88 |
Correct |
164 ms |
29656 KB |
answer = YES |
89 |
Correct |
115 ms |
26960 KB |
answer = YES |
90 |
Correct |
127 ms |
26960 KB |
answer = YES |
91 |
Correct |
154 ms |
26708 KB |
answer = YES |
92 |
Correct |
63 ms |
18064 KB |
answer = YES |
93 |
Correct |
62 ms |
17868 KB |
answer = YES |
94 |
Correct |
127 ms |
34768 KB |
answer = NO |
95 |
Correct |
90 ms |
26452 KB |
answer = NO |
96 |
Correct |
198 ms |
30416 KB |
answer = YES |
97 |
Correct |
77 ms |
34768 KB |
answer = NO |