# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
283507 |
2020-08-25T21:30:35 Z |
sofapuden |
Graph (BOI20_graph) |
C++14 |
|
415 ms |
29556 KB |
#include <bits/stdc++.h>
using namespace std;
typedef double db;
int n, m;
vector<vector<pair<int,int>>> gra;
vector<db> ans;
vector<int> colors;
vector<int> nums;
set<int> ansvis, recvis, fillvis;
db sum;
int index1;
void ansfill(int ind, db val){
ansvis.insert(ind);
ans[ind] = val;
for(int i = 0; i < (int)gra[ind].size(); ++i){
if(ans[gra[ind][i].first] == -0.25)ansfill(gra[ind][i].first, gra[ind][i].second - val);
else if(val+ans[gra[ind][i].first] != gra[ind][i].second){
cout << "NO\n";
exit(0);
}
}
}
int rec(int ind, int k){
recvis.insert(ind);
colors[ind] = k;
for(int i = 0; i < (int)gra[ind].size(); ++i){
if(recvis.count(gra[ind][i].first)){
if(k == colors[gra[ind][i].first]){
sum+=gra[ind][i].second;
index1 = gra[ind][i].first;
if(ind == index1)return -2;
return gra[ind][i].first;
}
}
else{
int v = rec(gra[ind][i].first, !k);
if(v == ind){
sum+=gra[ind][i].second;
return -2;
}
if(v == -1)continue;
if(v == -2)return v;
sum+=gra[ind][i].second*(k == colors[v] ? 1 : -1);
return v;
}
}
return -1;
}
void recfill(int ind, int k, int val){
fillvis.insert(ind);
nums.push_back(val * (k ? 1 : -1));
for(int i = 0; i < (int)gra[ind].size(); ++i){
if(!fillvis.count(gra[ind][i].first)){
recfill(gra[ind][i].first, !k, gra[ind][i].second - val);
}
}
}
void fill(int ind){
nums.clear();
recfill(ind, 0, 0);
sort(nums.begin(), nums.end());
ansfill(ind, nums[nums.size()/2]);
}
int check(int ind){
sum = 0;
index1 = -1;
int v = rec(ind, 0);
if(v == -1)return 0;
ansfill(index1, sum/2);
return 1;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
gra.resize(n);
ans.resize(n, -0.25);
colors.resize(n, -1);
while(m--){
int nm1, nm2, nm3; cin >> nm1 >> nm2 >> nm3;
nm1--; nm2--;
gra[nm1].push_back(make_pair(nm2, nm3));
gra[nm2].push_back(make_pair(nm1, nm3));
}
for(int i = 0; i < n; ++i){
if(!ansvis.count(i)){
if(!check(i))fill(i);
}
}
cout << "YES\n";
for(db i : ans)cout << i << " ";
cout << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
answer = YES |
2 |
Correct |
1 ms |
384 KB |
answer = YES |
3 |
Correct |
1 ms |
384 KB |
answer = YES |
4 |
Correct |
1 ms |
384 KB |
answer = NO |
5 |
Correct |
1 ms |
384 KB |
answer = YES |
6 |
Correct |
0 ms |
384 KB |
answer = YES |
7 |
Correct |
1 ms |
384 KB |
answer = YES |
8 |
Correct |
0 ms |
384 KB |
answer = YES |
9 |
Correct |
1 ms |
384 KB |
answer = NO |
10 |
Correct |
0 ms |
384 KB |
answer = YES |
11 |
Correct |
1 ms |
384 KB |
answer = YES |
12 |
Correct |
0 ms |
384 KB |
answer = NO |
13 |
Correct |
1 ms |
384 KB |
answer = YES |
14 |
Correct |
0 ms |
384 KB |
answer = YES |
15 |
Correct |
0 ms |
384 KB |
answer = YES |
16 |
Correct |
0 ms |
384 KB |
answer = YES |
17 |
Correct |
1 ms |
384 KB |
answer = YES |
18 |
Correct |
1 ms |
384 KB |
answer = YES |
19 |
Correct |
0 ms |
384 KB |
answer = YES |
20 |
Correct |
0 ms |
384 KB |
answer = YES |
21 |
Correct |
0 ms |
384 KB |
answer = YES |
22 |
Correct |
1 ms |
384 KB |
answer = NO |
23 |
Correct |
0 ms |
384 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
answer = YES |
2 |
Correct |
1 ms |
384 KB |
answer = YES |
3 |
Correct |
1 ms |
384 KB |
answer = YES |
4 |
Correct |
1 ms |
384 KB |
answer = NO |
5 |
Correct |
1 ms |
384 KB |
answer = YES |
6 |
Correct |
0 ms |
384 KB |
answer = YES |
7 |
Correct |
1 ms |
384 KB |
answer = YES |
8 |
Correct |
0 ms |
384 KB |
answer = YES |
9 |
Correct |
1 ms |
384 KB |
answer = NO |
10 |
Correct |
0 ms |
384 KB |
answer = YES |
11 |
Correct |
1 ms |
384 KB |
answer = YES |
12 |
Correct |
0 ms |
384 KB |
answer = NO |
13 |
Correct |
1 ms |
384 KB |
answer = YES |
14 |
Correct |
0 ms |
384 KB |
answer = YES |
15 |
Correct |
0 ms |
384 KB |
answer = YES |
16 |
Correct |
0 ms |
384 KB |
answer = YES |
17 |
Correct |
1 ms |
384 KB |
answer = YES |
18 |
Correct |
1 ms |
384 KB |
answer = YES |
19 |
Correct |
0 ms |
384 KB |
answer = YES |
20 |
Correct |
0 ms |
384 KB |
answer = YES |
21 |
Correct |
0 ms |
384 KB |
answer = YES |
22 |
Correct |
1 ms |
384 KB |
answer = NO |
23 |
Correct |
0 ms |
384 KB |
answer = NO |
24 |
Correct |
1 ms |
384 KB |
answer = YES |
25 |
Correct |
1 ms |
384 KB |
answer = YES |
26 |
Correct |
1 ms |
384 KB |
answer = YES |
27 |
Correct |
1 ms |
384 KB |
answer = YES |
28 |
Correct |
1 ms |
384 KB |
answer = YES |
29 |
Correct |
1 ms |
384 KB |
answer = YES |
30 |
Correct |
1 ms |
384 KB |
answer = NO |
31 |
Correct |
1 ms |
384 KB |
answer = YES |
32 |
Correct |
1 ms |
384 KB |
answer = YES |
33 |
Correct |
1 ms |
384 KB |
answer = YES |
34 |
Correct |
1 ms |
384 KB |
answer = YES |
35 |
Correct |
1 ms |
384 KB |
answer = YES |
36 |
Correct |
1 ms |
384 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
answer = YES |
2 |
Correct |
1 ms |
384 KB |
answer = YES |
3 |
Correct |
1 ms |
384 KB |
answer = YES |
4 |
Correct |
1 ms |
384 KB |
answer = NO |
5 |
Correct |
1 ms |
384 KB |
answer = YES |
6 |
Correct |
0 ms |
384 KB |
answer = YES |
7 |
Correct |
1 ms |
384 KB |
answer = YES |
8 |
Correct |
0 ms |
384 KB |
answer = YES |
9 |
Correct |
1 ms |
384 KB |
answer = NO |
10 |
Correct |
0 ms |
384 KB |
answer = YES |
11 |
Correct |
1 ms |
384 KB |
answer = YES |
12 |
Correct |
0 ms |
384 KB |
answer = NO |
13 |
Correct |
1 ms |
384 KB |
answer = YES |
14 |
Correct |
0 ms |
384 KB |
answer = YES |
15 |
Correct |
0 ms |
384 KB |
answer = YES |
16 |
Correct |
0 ms |
384 KB |
answer = YES |
17 |
Correct |
1 ms |
384 KB |
answer = YES |
18 |
Correct |
1 ms |
384 KB |
answer = YES |
19 |
Correct |
0 ms |
384 KB |
answer = YES |
20 |
Correct |
0 ms |
384 KB |
answer = YES |
21 |
Correct |
0 ms |
384 KB |
answer = YES |
22 |
Correct |
1 ms |
384 KB |
answer = NO |
23 |
Correct |
0 ms |
384 KB |
answer = NO |
24 |
Correct |
1 ms |
384 KB |
answer = YES |
25 |
Correct |
1 ms |
384 KB |
answer = YES |
26 |
Correct |
1 ms |
384 KB |
answer = YES |
27 |
Correct |
1 ms |
384 KB |
answer = YES |
28 |
Correct |
1 ms |
384 KB |
answer = YES |
29 |
Correct |
1 ms |
384 KB |
answer = YES |
30 |
Correct |
1 ms |
384 KB |
answer = NO |
31 |
Correct |
1 ms |
384 KB |
answer = YES |
32 |
Correct |
1 ms |
384 KB |
answer = YES |
33 |
Correct |
1 ms |
384 KB |
answer = YES |
34 |
Correct |
1 ms |
384 KB |
answer = YES |
35 |
Correct |
1 ms |
384 KB |
answer = YES |
36 |
Correct |
1 ms |
384 KB |
answer = YES |
37 |
Correct |
1 ms |
384 KB |
answer = YES |
38 |
Correct |
1 ms |
384 KB |
answer = YES |
39 |
Correct |
1 ms |
512 KB |
answer = YES |
40 |
Correct |
2 ms |
512 KB |
answer = YES |
41 |
Correct |
2 ms |
512 KB |
answer = NO |
42 |
Correct |
2 ms |
512 KB |
answer = YES |
43 |
Correct |
2 ms |
512 KB |
answer = YES |
44 |
Correct |
2 ms |
544 KB |
answer = YES |
45 |
Correct |
2 ms |
512 KB |
answer = YES |
46 |
Correct |
1 ms |
384 KB |
answer = YES |
47 |
Correct |
2 ms |
512 KB |
answer = YES |
48 |
Correct |
2 ms |
512 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
answer = YES |
2 |
Correct |
1 ms |
384 KB |
answer = YES |
3 |
Correct |
1 ms |
384 KB |
answer = YES |
4 |
Correct |
1 ms |
384 KB |
answer = NO |
5 |
Correct |
1 ms |
384 KB |
answer = YES |
6 |
Correct |
0 ms |
384 KB |
answer = YES |
7 |
Correct |
1 ms |
384 KB |
answer = YES |
8 |
Correct |
0 ms |
384 KB |
answer = YES |
9 |
Correct |
1 ms |
384 KB |
answer = NO |
10 |
Correct |
0 ms |
384 KB |
answer = YES |
11 |
Correct |
1 ms |
384 KB |
answer = YES |
12 |
Correct |
0 ms |
384 KB |
answer = NO |
13 |
Correct |
1 ms |
384 KB |
answer = YES |
14 |
Correct |
0 ms |
384 KB |
answer = YES |
15 |
Correct |
0 ms |
384 KB |
answer = YES |
16 |
Correct |
0 ms |
384 KB |
answer = YES |
17 |
Correct |
1 ms |
384 KB |
answer = YES |
18 |
Correct |
1 ms |
384 KB |
answer = YES |
19 |
Correct |
0 ms |
384 KB |
answer = YES |
20 |
Correct |
0 ms |
384 KB |
answer = YES |
21 |
Correct |
0 ms |
384 KB |
answer = YES |
22 |
Correct |
1 ms |
384 KB |
answer = NO |
23 |
Correct |
0 ms |
384 KB |
answer = NO |
24 |
Correct |
1 ms |
384 KB |
answer = YES |
25 |
Correct |
1 ms |
384 KB |
answer = YES |
26 |
Correct |
1 ms |
384 KB |
answer = YES |
27 |
Correct |
1 ms |
384 KB |
answer = YES |
28 |
Correct |
1 ms |
384 KB |
answer = YES |
29 |
Correct |
1 ms |
384 KB |
answer = YES |
30 |
Correct |
1 ms |
384 KB |
answer = NO |
31 |
Correct |
1 ms |
384 KB |
answer = YES |
32 |
Correct |
1 ms |
384 KB |
answer = YES |
33 |
Correct |
1 ms |
384 KB |
answer = YES |
34 |
Correct |
1 ms |
384 KB |
answer = YES |
35 |
Correct |
1 ms |
384 KB |
answer = YES |
36 |
Correct |
1 ms |
384 KB |
answer = YES |
37 |
Correct |
1 ms |
384 KB |
answer = YES |
38 |
Correct |
1 ms |
384 KB |
answer = YES |
39 |
Correct |
1 ms |
512 KB |
answer = YES |
40 |
Correct |
2 ms |
512 KB |
answer = YES |
41 |
Correct |
2 ms |
512 KB |
answer = NO |
42 |
Correct |
2 ms |
512 KB |
answer = YES |
43 |
Correct |
2 ms |
512 KB |
answer = YES |
44 |
Correct |
2 ms |
544 KB |
answer = YES |
45 |
Correct |
2 ms |
512 KB |
answer = YES |
46 |
Correct |
1 ms |
384 KB |
answer = YES |
47 |
Correct |
2 ms |
512 KB |
answer = YES |
48 |
Correct |
2 ms |
512 KB |
answer = YES |
49 |
Correct |
22 ms |
2688 KB |
answer = YES |
50 |
Correct |
20 ms |
2424 KB |
answer = YES |
51 |
Correct |
23 ms |
2944 KB |
answer = YES |
52 |
Correct |
15 ms |
2432 KB |
answer = NO |
53 |
Correct |
3 ms |
512 KB |
answer = YES |
54 |
Correct |
5 ms |
896 KB |
answer = YES |
55 |
Correct |
11 ms |
1536 KB |
answer = YES |
56 |
Correct |
23 ms |
2688 KB |
answer = YES |
57 |
Correct |
25 ms |
2560 KB |
answer = YES |
58 |
Correct |
19 ms |
2432 KB |
answer = YES |
59 |
Correct |
13 ms |
1920 KB |
answer = YES |
60 |
Correct |
22 ms |
2688 KB |
answer = YES |
61 |
Correct |
8 ms |
1184 KB |
answer = YES |
62 |
Correct |
68 ms |
7672 KB |
answer = NO |
63 |
Correct |
74 ms |
7800 KB |
answer = YES |
64 |
Correct |
67 ms |
7800 KB |
answer = NO |
65 |
Correct |
74 ms |
7800 KB |
answer = YES |
66 |
Correct |
4 ms |
768 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
answer = YES |
2 |
Correct |
1 ms |
384 KB |
answer = YES |
3 |
Correct |
1 ms |
384 KB |
answer = YES |
4 |
Correct |
1 ms |
384 KB |
answer = NO |
5 |
Correct |
1 ms |
384 KB |
answer = YES |
6 |
Correct |
0 ms |
384 KB |
answer = YES |
7 |
Correct |
1 ms |
384 KB |
answer = YES |
8 |
Correct |
0 ms |
384 KB |
answer = YES |
9 |
Correct |
1 ms |
384 KB |
answer = NO |
10 |
Correct |
0 ms |
384 KB |
answer = YES |
11 |
Correct |
1 ms |
384 KB |
answer = YES |
12 |
Correct |
0 ms |
384 KB |
answer = NO |
13 |
Correct |
1 ms |
384 KB |
answer = YES |
14 |
Correct |
0 ms |
384 KB |
answer = YES |
15 |
Correct |
0 ms |
384 KB |
answer = YES |
16 |
Correct |
0 ms |
384 KB |
answer = YES |
17 |
Correct |
1 ms |
384 KB |
answer = YES |
18 |
Correct |
1 ms |
384 KB |
answer = YES |
19 |
Correct |
0 ms |
384 KB |
answer = YES |
20 |
Correct |
0 ms |
384 KB |
answer = YES |
21 |
Correct |
0 ms |
384 KB |
answer = YES |
22 |
Correct |
1 ms |
384 KB |
answer = NO |
23 |
Correct |
0 ms |
384 KB |
answer = NO |
24 |
Correct |
1 ms |
384 KB |
answer = YES |
25 |
Correct |
1 ms |
384 KB |
answer = YES |
26 |
Correct |
1 ms |
384 KB |
answer = YES |
27 |
Correct |
1 ms |
384 KB |
answer = YES |
28 |
Correct |
1 ms |
384 KB |
answer = YES |
29 |
Correct |
1 ms |
384 KB |
answer = YES |
30 |
Correct |
1 ms |
384 KB |
answer = NO |
31 |
Correct |
1 ms |
384 KB |
answer = YES |
32 |
Correct |
1 ms |
384 KB |
answer = YES |
33 |
Correct |
1 ms |
384 KB |
answer = YES |
34 |
Correct |
1 ms |
384 KB |
answer = YES |
35 |
Correct |
1 ms |
384 KB |
answer = YES |
36 |
Correct |
1 ms |
384 KB |
answer = YES |
37 |
Correct |
1 ms |
384 KB |
answer = YES |
38 |
Correct |
1 ms |
384 KB |
answer = YES |
39 |
Correct |
1 ms |
512 KB |
answer = YES |
40 |
Correct |
2 ms |
512 KB |
answer = YES |
41 |
Correct |
2 ms |
512 KB |
answer = NO |
42 |
Correct |
2 ms |
512 KB |
answer = YES |
43 |
Correct |
2 ms |
512 KB |
answer = YES |
44 |
Correct |
2 ms |
544 KB |
answer = YES |
45 |
Correct |
2 ms |
512 KB |
answer = YES |
46 |
Correct |
1 ms |
384 KB |
answer = YES |
47 |
Correct |
2 ms |
512 KB |
answer = YES |
48 |
Correct |
2 ms |
512 KB |
answer = YES |
49 |
Correct |
22 ms |
2688 KB |
answer = YES |
50 |
Correct |
20 ms |
2424 KB |
answer = YES |
51 |
Correct |
23 ms |
2944 KB |
answer = YES |
52 |
Correct |
15 ms |
2432 KB |
answer = NO |
53 |
Correct |
3 ms |
512 KB |
answer = YES |
54 |
Correct |
5 ms |
896 KB |
answer = YES |
55 |
Correct |
11 ms |
1536 KB |
answer = YES |
56 |
Correct |
23 ms |
2688 KB |
answer = YES |
57 |
Correct |
25 ms |
2560 KB |
answer = YES |
58 |
Correct |
19 ms |
2432 KB |
answer = YES |
59 |
Correct |
13 ms |
1920 KB |
answer = YES |
60 |
Correct |
22 ms |
2688 KB |
answer = YES |
61 |
Correct |
8 ms |
1184 KB |
answer = YES |
62 |
Correct |
68 ms |
7672 KB |
answer = NO |
63 |
Correct |
74 ms |
7800 KB |
answer = YES |
64 |
Correct |
67 ms |
7800 KB |
answer = NO |
65 |
Correct |
74 ms |
7800 KB |
answer = YES |
66 |
Correct |
4 ms |
768 KB |
answer = YES |
67 |
Correct |
215 ms |
29424 KB |
answer = YES |
68 |
Correct |
202 ms |
29424 KB |
answer = YES |
69 |
Correct |
151 ms |
22800 KB |
answer = YES |
70 |
Correct |
195 ms |
27120 KB |
answer = YES |
71 |
Correct |
172 ms |
22904 KB |
answer = YES |
72 |
Correct |
393 ms |
23664 KB |
answer = YES |
73 |
Correct |
210 ms |
16120 KB |
answer = YES |
74 |
Correct |
116 ms |
11768 KB |
answer = YES |
75 |
Correct |
150 ms |
16372 KB |
answer = NO |
76 |
Correct |
28 ms |
3200 KB |
answer = YES |
77 |
Correct |
64 ms |
6136 KB |
answer = YES |
78 |
Correct |
135 ms |
10356 KB |
answer = YES |
79 |
Correct |
284 ms |
20316 KB |
answer = YES |
80 |
Correct |
196 ms |
18548 KB |
answer = YES |
81 |
Correct |
118 ms |
16632 KB |
answer = NO |
82 |
Correct |
189 ms |
18936 KB |
answer = YES |
83 |
Correct |
277 ms |
23052 KB |
answer = YES |
84 |
Correct |
415 ms |
29556 KB |
answer = YES |
85 |
Correct |
201 ms |
29468 KB |
answer = YES |
86 |
Correct |
173 ms |
22764 KB |
answer = YES |
87 |
Correct |
152 ms |
15480 KB |
answer = NO |
88 |
Correct |
290 ms |
20472 KB |
answer = YES |
89 |
Correct |
246 ms |
18276 KB |
answer = YES |
90 |
Correct |
235 ms |
18040 KB |
answer = YES |
91 |
Correct |
264 ms |
18040 KB |
answer = YES |
92 |
Correct |
89 ms |
8440 KB |
answer = YES |
93 |
Correct |
93 ms |
8312 KB |
answer = YES |
94 |
Correct |
390 ms |
29040 KB |
answer = NO |
95 |
Correct |
67 ms |
9592 KB |
answer = NO |
96 |
Correct |
335 ms |
19788 KB |
answer = YES |
97 |
Correct |
161 ms |
29040 KB |
answer = NO |