# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
650580 |
2022-10-14T08:40:24 Z |
welleyth |
Graph (BOI20_graph) |
C++17 |
|
700 ms |
84928 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define mp make_pair
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
constexpr int N = (int)(1 << 21);
constexpr int md = (int)2e5 + 111;
constexpr int INF = (int)1e18 + 111;
constexpr int K = (int)2;
mt19937 rnd(time(nullptr));
bool used[N];
int val[N];
vector<pair<int,int>> g[N];
bool can = true;
int S = 0;
void dfs(int v){
if(!can)
return;
used[v] = 1;
set<int> st[3];
for(auto&[to,w] : g[v]){
if(used[to]){
st[w].insert(val[to]);
continue;
}
}
if(st[1].size() > 1 || st[2].size() > 1){
can = false;
return;
}
if(!st[1].empty() && !st[2].empty() && *st[2].begin()-*st[1].begin() != K){
can = false;
return;
}
if(st[1].empty() && st[2].empty()){
val[v] = S;
} else if(!st[1].empty()){
val[v] = K - *st[1].begin();
} else if(!st[2].empty()){
val[v] = 2*K - *st[2].begin();
}
for(auto&[to,w] : g[v]){
if(!used[to])
dfs(to);
}
return;
}
bool U[N];
vector<int> component;
void dfs2(int v){
U[v] = true;
component.pb(v);
for(auto&[to,w] : g[v]){
if(!U[to]){
dfs2(to);
}
}
return;
}
void solve(){
int n,m;
cin >> n >> m;
for(int i = 0; i < m; i++){
int a,b,c;
cin >> a >> b >> c;
g[a].pb(mp(b,c));
g[b].pb(mp(a,c));
}
vector<int> smallestSum;
int mn = INF;
int ans[n+1];
memset(ans,0,sizeof ans);
for(int i = 1; i <= n; i++){
if(!U[i]){
component.clear();
dfs2(i);
int mn = INF;
for(int j = -100; j <= 100; j++){
S = j;
can = true;
for(auto& v : component) used[v] = false;
for(auto& v : component){
for(auto&[to,w] : g[v]){
if(to == v){
val[v] = w*K/2;
used[v] = true;
}
}
}
for(auto& v : component){
if(!used[v])
dfs(v);
}
if(!can)
continue;
int sum = 0;
for(auto& v : component){
sum += abs(val[v]);
}
if(sum < mn){
mn = sum;
for(auto& v : component)
ans[v] = val[v];
}
}
if(mn == INF){
cout << "NO\n";
return;
}
}
}
cout << "YES\n";
for(int i = 1; i <= n; i++)
cout << 1.0*ans[i]/K << " ";
cout << "\n";
return;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
// init();
int tests = 1;
// cin >> tests;
for(int test = 1; test <= tests; test++){
// cerr << "test = " << test << "\n";
solve();
}
return 0;
}
/**
**/
Compilation message
Graph.cpp: In function 'void solve()':
Graph.cpp:87:9: warning: unused variable 'mn' [-Wunused-variable]
87 | int mn = INF;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
49484 KB |
answer = YES |
2 |
Correct |
30 ms |
49480 KB |
answer = YES |
3 |
Correct |
23 ms |
49588 KB |
answer = YES |
4 |
Correct |
26 ms |
49492 KB |
answer = NO |
5 |
Correct |
24 ms |
49504 KB |
answer = YES |
6 |
Correct |
24 ms |
49588 KB |
answer = YES |
7 |
Correct |
25 ms |
49504 KB |
answer = YES |
8 |
Correct |
25 ms |
49520 KB |
answer = YES |
9 |
Correct |
23 ms |
49580 KB |
answer = NO |
10 |
Correct |
28 ms |
49644 KB |
answer = YES |
11 |
Correct |
24 ms |
49548 KB |
answer = YES |
12 |
Correct |
24 ms |
49540 KB |
answer = NO |
13 |
Correct |
25 ms |
49612 KB |
answer = YES |
14 |
Correct |
26 ms |
49580 KB |
answer = YES |
15 |
Correct |
24 ms |
49512 KB |
answer = YES |
16 |
Correct |
25 ms |
49516 KB |
answer = YES |
17 |
Correct |
28 ms |
49472 KB |
answer = YES |
18 |
Correct |
25 ms |
49544 KB |
answer = YES |
19 |
Correct |
26 ms |
49492 KB |
answer = YES |
20 |
Correct |
25 ms |
49552 KB |
answer = YES |
21 |
Correct |
25 ms |
49476 KB |
answer = YES |
22 |
Correct |
23 ms |
49492 KB |
answer = NO |
23 |
Correct |
25 ms |
49488 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
49484 KB |
answer = YES |
2 |
Correct |
30 ms |
49480 KB |
answer = YES |
3 |
Correct |
23 ms |
49588 KB |
answer = YES |
4 |
Correct |
26 ms |
49492 KB |
answer = NO |
5 |
Correct |
24 ms |
49504 KB |
answer = YES |
6 |
Correct |
24 ms |
49588 KB |
answer = YES |
7 |
Correct |
25 ms |
49504 KB |
answer = YES |
8 |
Correct |
25 ms |
49520 KB |
answer = YES |
9 |
Correct |
23 ms |
49580 KB |
answer = NO |
10 |
Correct |
28 ms |
49644 KB |
answer = YES |
11 |
Correct |
24 ms |
49548 KB |
answer = YES |
12 |
Correct |
24 ms |
49540 KB |
answer = NO |
13 |
Correct |
25 ms |
49612 KB |
answer = YES |
14 |
Correct |
26 ms |
49580 KB |
answer = YES |
15 |
Correct |
24 ms |
49512 KB |
answer = YES |
16 |
Correct |
25 ms |
49516 KB |
answer = YES |
17 |
Correct |
28 ms |
49472 KB |
answer = YES |
18 |
Correct |
25 ms |
49544 KB |
answer = YES |
19 |
Correct |
26 ms |
49492 KB |
answer = YES |
20 |
Correct |
25 ms |
49552 KB |
answer = YES |
21 |
Correct |
25 ms |
49476 KB |
answer = YES |
22 |
Correct |
23 ms |
49492 KB |
answer = NO |
23 |
Correct |
25 ms |
49488 KB |
answer = NO |
24 |
Correct |
25 ms |
49492 KB |
answer = YES |
25 |
Correct |
25 ms |
49560 KB |
answer = YES |
26 |
Correct |
26 ms |
49492 KB |
answer = YES |
27 |
Correct |
24 ms |
49504 KB |
answer = YES |
28 |
Correct |
25 ms |
49476 KB |
answer = YES |
29 |
Correct |
26 ms |
49616 KB |
answer = YES |
30 |
Correct |
24 ms |
49492 KB |
answer = NO |
31 |
Correct |
24 ms |
49596 KB |
answer = YES |
32 |
Correct |
26 ms |
49524 KB |
answer = YES |
33 |
Correct |
25 ms |
49544 KB |
answer = YES |
34 |
Correct |
24 ms |
49544 KB |
answer = YES |
35 |
Correct |
25 ms |
49568 KB |
answer = YES |
36 |
Correct |
25 ms |
49492 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
49484 KB |
answer = YES |
2 |
Correct |
30 ms |
49480 KB |
answer = YES |
3 |
Correct |
23 ms |
49588 KB |
answer = YES |
4 |
Correct |
26 ms |
49492 KB |
answer = NO |
5 |
Correct |
24 ms |
49504 KB |
answer = YES |
6 |
Correct |
24 ms |
49588 KB |
answer = YES |
7 |
Correct |
25 ms |
49504 KB |
answer = YES |
8 |
Correct |
25 ms |
49520 KB |
answer = YES |
9 |
Correct |
23 ms |
49580 KB |
answer = NO |
10 |
Correct |
28 ms |
49644 KB |
answer = YES |
11 |
Correct |
24 ms |
49548 KB |
answer = YES |
12 |
Correct |
24 ms |
49540 KB |
answer = NO |
13 |
Correct |
25 ms |
49612 KB |
answer = YES |
14 |
Correct |
26 ms |
49580 KB |
answer = YES |
15 |
Correct |
24 ms |
49512 KB |
answer = YES |
16 |
Correct |
25 ms |
49516 KB |
answer = YES |
17 |
Correct |
28 ms |
49472 KB |
answer = YES |
18 |
Correct |
25 ms |
49544 KB |
answer = YES |
19 |
Correct |
26 ms |
49492 KB |
answer = YES |
20 |
Correct |
25 ms |
49552 KB |
answer = YES |
21 |
Correct |
25 ms |
49476 KB |
answer = YES |
22 |
Correct |
23 ms |
49492 KB |
answer = NO |
23 |
Correct |
25 ms |
49488 KB |
answer = NO |
24 |
Correct |
25 ms |
49492 KB |
answer = YES |
25 |
Correct |
25 ms |
49560 KB |
answer = YES |
26 |
Correct |
26 ms |
49492 KB |
answer = YES |
27 |
Correct |
24 ms |
49504 KB |
answer = YES |
28 |
Correct |
25 ms |
49476 KB |
answer = YES |
29 |
Correct |
26 ms |
49616 KB |
answer = YES |
30 |
Correct |
24 ms |
49492 KB |
answer = NO |
31 |
Correct |
24 ms |
49596 KB |
answer = YES |
32 |
Correct |
26 ms |
49524 KB |
answer = YES |
33 |
Correct |
25 ms |
49544 KB |
answer = YES |
34 |
Correct |
24 ms |
49544 KB |
answer = YES |
35 |
Correct |
25 ms |
49568 KB |
answer = YES |
36 |
Correct |
25 ms |
49492 KB |
answer = YES |
37 |
Correct |
33 ms |
49516 KB |
answer = YES |
38 |
Correct |
25 ms |
49492 KB |
answer = YES |
39 |
Correct |
32 ms |
49620 KB |
answer = YES |
40 |
Correct |
36 ms |
49656 KB |
answer = YES |
41 |
Correct |
32 ms |
49720 KB |
answer = NO |
42 |
Correct |
39 ms |
49620 KB |
answer = YES |
43 |
Correct |
39 ms |
49652 KB |
answer = YES |
44 |
Correct |
38 ms |
49620 KB |
answer = YES |
45 |
Correct |
36 ms |
49608 KB |
answer = YES |
46 |
Correct |
31 ms |
49628 KB |
answer = YES |
47 |
Correct |
28 ms |
49644 KB |
answer = YES |
48 |
Correct |
30 ms |
49664 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
49484 KB |
answer = YES |
2 |
Correct |
30 ms |
49480 KB |
answer = YES |
3 |
Correct |
23 ms |
49588 KB |
answer = YES |
4 |
Correct |
26 ms |
49492 KB |
answer = NO |
5 |
Correct |
24 ms |
49504 KB |
answer = YES |
6 |
Correct |
24 ms |
49588 KB |
answer = YES |
7 |
Correct |
25 ms |
49504 KB |
answer = YES |
8 |
Correct |
25 ms |
49520 KB |
answer = YES |
9 |
Correct |
23 ms |
49580 KB |
answer = NO |
10 |
Correct |
28 ms |
49644 KB |
answer = YES |
11 |
Correct |
24 ms |
49548 KB |
answer = YES |
12 |
Correct |
24 ms |
49540 KB |
answer = NO |
13 |
Correct |
25 ms |
49612 KB |
answer = YES |
14 |
Correct |
26 ms |
49580 KB |
answer = YES |
15 |
Correct |
24 ms |
49512 KB |
answer = YES |
16 |
Correct |
25 ms |
49516 KB |
answer = YES |
17 |
Correct |
28 ms |
49472 KB |
answer = YES |
18 |
Correct |
25 ms |
49544 KB |
answer = YES |
19 |
Correct |
26 ms |
49492 KB |
answer = YES |
20 |
Correct |
25 ms |
49552 KB |
answer = YES |
21 |
Correct |
25 ms |
49476 KB |
answer = YES |
22 |
Correct |
23 ms |
49492 KB |
answer = NO |
23 |
Correct |
25 ms |
49488 KB |
answer = NO |
24 |
Correct |
25 ms |
49492 KB |
answer = YES |
25 |
Correct |
25 ms |
49560 KB |
answer = YES |
26 |
Correct |
26 ms |
49492 KB |
answer = YES |
27 |
Correct |
24 ms |
49504 KB |
answer = YES |
28 |
Correct |
25 ms |
49476 KB |
answer = YES |
29 |
Correct |
26 ms |
49616 KB |
answer = YES |
30 |
Correct |
24 ms |
49492 KB |
answer = NO |
31 |
Correct |
24 ms |
49596 KB |
answer = YES |
32 |
Correct |
26 ms |
49524 KB |
answer = YES |
33 |
Correct |
25 ms |
49544 KB |
answer = YES |
34 |
Correct |
24 ms |
49544 KB |
answer = YES |
35 |
Correct |
25 ms |
49568 KB |
answer = YES |
36 |
Correct |
25 ms |
49492 KB |
answer = YES |
37 |
Correct |
33 ms |
49516 KB |
answer = YES |
38 |
Correct |
25 ms |
49492 KB |
answer = YES |
39 |
Correct |
32 ms |
49620 KB |
answer = YES |
40 |
Correct |
36 ms |
49656 KB |
answer = YES |
41 |
Correct |
32 ms |
49720 KB |
answer = NO |
42 |
Correct |
39 ms |
49620 KB |
answer = YES |
43 |
Correct |
39 ms |
49652 KB |
answer = YES |
44 |
Correct |
38 ms |
49620 KB |
answer = YES |
45 |
Correct |
36 ms |
49608 KB |
answer = YES |
46 |
Correct |
31 ms |
49628 KB |
answer = YES |
47 |
Correct |
28 ms |
49644 KB |
answer = YES |
48 |
Correct |
30 ms |
49664 KB |
answer = YES |
49 |
Correct |
208 ms |
50480 KB |
answer = YES |
50 |
Correct |
181 ms |
51924 KB |
answer = YES |
51 |
Correct |
185 ms |
51904 KB |
answer = YES |
52 |
Correct |
65 ms |
50508 KB |
answer = NO |
53 |
Correct |
40 ms |
49612 KB |
answer = YES |
54 |
Correct |
63 ms |
49796 KB |
answer = YES |
55 |
Correct |
125 ms |
49940 KB |
answer = YES |
56 |
Correct |
192 ms |
50468 KB |
answer = YES |
57 |
Correct |
166 ms |
50260 KB |
answer = YES |
58 |
Correct |
163 ms |
50260 KB |
answer = YES |
59 |
Correct |
129 ms |
50252 KB |
answer = YES |
60 |
Correct |
189 ms |
50388 KB |
answer = YES |
61 |
Correct |
90 ms |
50032 KB |
answer = YES |
62 |
Correct |
300 ms |
59224 KB |
answer = NO |
63 |
Correct |
273 ms |
60788 KB |
answer = YES |
64 |
Correct |
272 ms |
60704 KB |
answer = NO |
65 |
Correct |
302 ms |
60772 KB |
answer = YES |
66 |
Correct |
50 ms |
49664 KB |
answer = YES |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
49484 KB |
answer = YES |
2 |
Correct |
30 ms |
49480 KB |
answer = YES |
3 |
Correct |
23 ms |
49588 KB |
answer = YES |
4 |
Correct |
26 ms |
49492 KB |
answer = NO |
5 |
Correct |
24 ms |
49504 KB |
answer = YES |
6 |
Correct |
24 ms |
49588 KB |
answer = YES |
7 |
Correct |
25 ms |
49504 KB |
answer = YES |
8 |
Correct |
25 ms |
49520 KB |
answer = YES |
9 |
Correct |
23 ms |
49580 KB |
answer = NO |
10 |
Correct |
28 ms |
49644 KB |
answer = YES |
11 |
Correct |
24 ms |
49548 KB |
answer = YES |
12 |
Correct |
24 ms |
49540 KB |
answer = NO |
13 |
Correct |
25 ms |
49612 KB |
answer = YES |
14 |
Correct |
26 ms |
49580 KB |
answer = YES |
15 |
Correct |
24 ms |
49512 KB |
answer = YES |
16 |
Correct |
25 ms |
49516 KB |
answer = YES |
17 |
Correct |
28 ms |
49472 KB |
answer = YES |
18 |
Correct |
25 ms |
49544 KB |
answer = YES |
19 |
Correct |
26 ms |
49492 KB |
answer = YES |
20 |
Correct |
25 ms |
49552 KB |
answer = YES |
21 |
Correct |
25 ms |
49476 KB |
answer = YES |
22 |
Correct |
23 ms |
49492 KB |
answer = NO |
23 |
Correct |
25 ms |
49488 KB |
answer = NO |
24 |
Correct |
25 ms |
49492 KB |
answer = YES |
25 |
Correct |
25 ms |
49560 KB |
answer = YES |
26 |
Correct |
26 ms |
49492 KB |
answer = YES |
27 |
Correct |
24 ms |
49504 KB |
answer = YES |
28 |
Correct |
25 ms |
49476 KB |
answer = YES |
29 |
Correct |
26 ms |
49616 KB |
answer = YES |
30 |
Correct |
24 ms |
49492 KB |
answer = NO |
31 |
Correct |
24 ms |
49596 KB |
answer = YES |
32 |
Correct |
26 ms |
49524 KB |
answer = YES |
33 |
Correct |
25 ms |
49544 KB |
answer = YES |
34 |
Correct |
24 ms |
49544 KB |
answer = YES |
35 |
Correct |
25 ms |
49568 KB |
answer = YES |
36 |
Correct |
25 ms |
49492 KB |
answer = YES |
37 |
Correct |
33 ms |
49516 KB |
answer = YES |
38 |
Correct |
25 ms |
49492 KB |
answer = YES |
39 |
Correct |
32 ms |
49620 KB |
answer = YES |
40 |
Correct |
36 ms |
49656 KB |
answer = YES |
41 |
Correct |
32 ms |
49720 KB |
answer = NO |
42 |
Correct |
39 ms |
49620 KB |
answer = YES |
43 |
Correct |
39 ms |
49652 KB |
answer = YES |
44 |
Correct |
38 ms |
49620 KB |
answer = YES |
45 |
Correct |
36 ms |
49608 KB |
answer = YES |
46 |
Correct |
31 ms |
49628 KB |
answer = YES |
47 |
Correct |
28 ms |
49644 KB |
answer = YES |
48 |
Correct |
30 ms |
49664 KB |
answer = YES |
49 |
Correct |
208 ms |
50480 KB |
answer = YES |
50 |
Correct |
181 ms |
51924 KB |
answer = YES |
51 |
Correct |
185 ms |
51904 KB |
answer = YES |
52 |
Correct |
65 ms |
50508 KB |
answer = NO |
53 |
Correct |
40 ms |
49612 KB |
answer = YES |
54 |
Correct |
63 ms |
49796 KB |
answer = YES |
55 |
Correct |
125 ms |
49940 KB |
answer = YES |
56 |
Correct |
192 ms |
50468 KB |
answer = YES |
57 |
Correct |
166 ms |
50260 KB |
answer = YES |
58 |
Correct |
163 ms |
50260 KB |
answer = YES |
59 |
Correct |
129 ms |
50252 KB |
answer = YES |
60 |
Correct |
189 ms |
50388 KB |
answer = YES |
61 |
Correct |
90 ms |
50032 KB |
answer = YES |
62 |
Correct |
300 ms |
59224 KB |
answer = NO |
63 |
Correct |
273 ms |
60788 KB |
answer = YES |
64 |
Correct |
272 ms |
60704 KB |
answer = NO |
65 |
Correct |
302 ms |
60772 KB |
answer = YES |
66 |
Correct |
50 ms |
49664 KB |
answer = YES |
67 |
Execution timed out |
1095 ms |
84928 KB |
Time limit exceeded |
68 |
Halted |
0 ms |
0 KB |
- |