# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
650571 |
2022-10-14T08:32:43 Z |
welleyth |
Graph (BOI20_graph) |
C++17 |
|
37 ms |
51660 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)6;
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;
}
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;
for(int j = -100; j <= 100; j++){
memset(used,0,sizeof used);
S = j;
can = true;
for(int i = 1; i <= n; i++){
for(auto&[to,w] : g[i]){
if(to == i){
val[i] = w*K/2;
used[i] = true;
}
}
}
for(int i = 1; i <= n; i++){
if(!used[i])
dfs(i);
}
if(!can)
continue;
int sum = 0;
for(int i = 1; i <= n; i++){
sum += abs(val[i]);
}
if(sum < mn){
mn = sum;
smallestSum.clear();
for(int i = 1; i <= n; i++){
smallestSum.pb(val[i]);
}
}
// cout << "YES\n";
// for(int i = 1; i <= n; i++)
// cout << val[i]/2.0 << " ";
// return;
}
if(mn == INF){
cout << "NO\n";
return;
}
cout << "YES\n";
for(auto& x : smallestSum)
cout << 1.0*x/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;
}
/**
**/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
51496 KB |
answer = YES |
2 |
Correct |
34 ms |
51532 KB |
answer = YES |
3 |
Correct |
35 ms |
51572 KB |
answer = YES |
4 |
Correct |
35 ms |
51612 KB |
answer = NO |
5 |
Correct |
34 ms |
51524 KB |
answer = YES |
6 |
Correct |
37 ms |
51540 KB |
answer = YES |
7 |
Correct |
37 ms |
51528 KB |
answer = YES |
8 |
Correct |
34 ms |
51532 KB |
answer = YES |
9 |
Correct |
33 ms |
51540 KB |
answer = NO |
10 |
Correct |
36 ms |
51560 KB |
answer = YES |
11 |
Correct |
35 ms |
51652 KB |
answer = YES |
12 |
Correct |
33 ms |
51540 KB |
answer = NO |
13 |
Correct |
36 ms |
51540 KB |
answer = YES |
14 |
Correct |
33 ms |
51540 KB |
answer = YES |
15 |
Correct |
34 ms |
51540 KB |
answer = YES |
16 |
Correct |
36 ms |
51608 KB |
answer = YES |
17 |
Correct |
34 ms |
51604 KB |
answer = YES |
18 |
Correct |
34 ms |
51612 KB |
answer = YES |
19 |
Correct |
35 ms |
51540 KB |
answer = YES |
20 |
Correct |
37 ms |
51508 KB |
answer = YES |
21 |
Correct |
35 ms |
51528 KB |
answer = YES |
22 |
Correct |
36 ms |
51532 KB |
answer = NO |
23 |
Correct |
35 ms |
51604 KB |
answer = NO |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
51496 KB |
answer = YES |
2 |
Correct |
34 ms |
51532 KB |
answer = YES |
3 |
Correct |
35 ms |
51572 KB |
answer = YES |
4 |
Correct |
35 ms |
51612 KB |
answer = NO |
5 |
Correct |
34 ms |
51524 KB |
answer = YES |
6 |
Correct |
37 ms |
51540 KB |
answer = YES |
7 |
Correct |
37 ms |
51528 KB |
answer = YES |
8 |
Correct |
34 ms |
51532 KB |
answer = YES |
9 |
Correct |
33 ms |
51540 KB |
answer = NO |
10 |
Correct |
36 ms |
51560 KB |
answer = YES |
11 |
Correct |
35 ms |
51652 KB |
answer = YES |
12 |
Correct |
33 ms |
51540 KB |
answer = NO |
13 |
Correct |
36 ms |
51540 KB |
answer = YES |
14 |
Correct |
33 ms |
51540 KB |
answer = YES |
15 |
Correct |
34 ms |
51540 KB |
answer = YES |
16 |
Correct |
36 ms |
51608 KB |
answer = YES |
17 |
Correct |
34 ms |
51604 KB |
answer = YES |
18 |
Correct |
34 ms |
51612 KB |
answer = YES |
19 |
Correct |
35 ms |
51540 KB |
answer = YES |
20 |
Correct |
37 ms |
51508 KB |
answer = YES |
21 |
Correct |
35 ms |
51528 KB |
answer = YES |
22 |
Correct |
36 ms |
51532 KB |
answer = NO |
23 |
Correct |
35 ms |
51604 KB |
answer = NO |
24 |
Correct |
35 ms |
51568 KB |
answer = YES |
25 |
Correct |
33 ms |
51568 KB |
answer = YES |
26 |
Correct |
37 ms |
51612 KB |
answer = YES |
27 |
Correct |
35 ms |
51660 KB |
answer = YES |
28 |
Correct |
35 ms |
51540 KB |
answer = YES |
29 |
Correct |
37 ms |
51616 KB |
answer = YES |
30 |
Correct |
34 ms |
51624 KB |
answer = NO |
31 |
Incorrect |
35 ms |
51568 KB |
participant answer is larger than the answer of jury |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
51496 KB |
answer = YES |
2 |
Correct |
34 ms |
51532 KB |
answer = YES |
3 |
Correct |
35 ms |
51572 KB |
answer = YES |
4 |
Correct |
35 ms |
51612 KB |
answer = NO |
5 |
Correct |
34 ms |
51524 KB |
answer = YES |
6 |
Correct |
37 ms |
51540 KB |
answer = YES |
7 |
Correct |
37 ms |
51528 KB |
answer = YES |
8 |
Correct |
34 ms |
51532 KB |
answer = YES |
9 |
Correct |
33 ms |
51540 KB |
answer = NO |
10 |
Correct |
36 ms |
51560 KB |
answer = YES |
11 |
Correct |
35 ms |
51652 KB |
answer = YES |
12 |
Correct |
33 ms |
51540 KB |
answer = NO |
13 |
Correct |
36 ms |
51540 KB |
answer = YES |
14 |
Correct |
33 ms |
51540 KB |
answer = YES |
15 |
Correct |
34 ms |
51540 KB |
answer = YES |
16 |
Correct |
36 ms |
51608 KB |
answer = YES |
17 |
Correct |
34 ms |
51604 KB |
answer = YES |
18 |
Correct |
34 ms |
51612 KB |
answer = YES |
19 |
Correct |
35 ms |
51540 KB |
answer = YES |
20 |
Correct |
37 ms |
51508 KB |
answer = YES |
21 |
Correct |
35 ms |
51528 KB |
answer = YES |
22 |
Correct |
36 ms |
51532 KB |
answer = NO |
23 |
Correct |
35 ms |
51604 KB |
answer = NO |
24 |
Correct |
35 ms |
51568 KB |
answer = YES |
25 |
Correct |
33 ms |
51568 KB |
answer = YES |
26 |
Correct |
37 ms |
51612 KB |
answer = YES |
27 |
Correct |
35 ms |
51660 KB |
answer = YES |
28 |
Correct |
35 ms |
51540 KB |
answer = YES |
29 |
Correct |
37 ms |
51616 KB |
answer = YES |
30 |
Correct |
34 ms |
51624 KB |
answer = NO |
31 |
Incorrect |
35 ms |
51568 KB |
participant answer is larger than the answer of jury |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
51496 KB |
answer = YES |
2 |
Correct |
34 ms |
51532 KB |
answer = YES |
3 |
Correct |
35 ms |
51572 KB |
answer = YES |
4 |
Correct |
35 ms |
51612 KB |
answer = NO |
5 |
Correct |
34 ms |
51524 KB |
answer = YES |
6 |
Correct |
37 ms |
51540 KB |
answer = YES |
7 |
Correct |
37 ms |
51528 KB |
answer = YES |
8 |
Correct |
34 ms |
51532 KB |
answer = YES |
9 |
Correct |
33 ms |
51540 KB |
answer = NO |
10 |
Correct |
36 ms |
51560 KB |
answer = YES |
11 |
Correct |
35 ms |
51652 KB |
answer = YES |
12 |
Correct |
33 ms |
51540 KB |
answer = NO |
13 |
Correct |
36 ms |
51540 KB |
answer = YES |
14 |
Correct |
33 ms |
51540 KB |
answer = YES |
15 |
Correct |
34 ms |
51540 KB |
answer = YES |
16 |
Correct |
36 ms |
51608 KB |
answer = YES |
17 |
Correct |
34 ms |
51604 KB |
answer = YES |
18 |
Correct |
34 ms |
51612 KB |
answer = YES |
19 |
Correct |
35 ms |
51540 KB |
answer = YES |
20 |
Correct |
37 ms |
51508 KB |
answer = YES |
21 |
Correct |
35 ms |
51528 KB |
answer = YES |
22 |
Correct |
36 ms |
51532 KB |
answer = NO |
23 |
Correct |
35 ms |
51604 KB |
answer = NO |
24 |
Correct |
35 ms |
51568 KB |
answer = YES |
25 |
Correct |
33 ms |
51568 KB |
answer = YES |
26 |
Correct |
37 ms |
51612 KB |
answer = YES |
27 |
Correct |
35 ms |
51660 KB |
answer = YES |
28 |
Correct |
35 ms |
51540 KB |
answer = YES |
29 |
Correct |
37 ms |
51616 KB |
answer = YES |
30 |
Correct |
34 ms |
51624 KB |
answer = NO |
31 |
Incorrect |
35 ms |
51568 KB |
participant answer is larger than the answer of jury |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
51496 KB |
answer = YES |
2 |
Correct |
34 ms |
51532 KB |
answer = YES |
3 |
Correct |
35 ms |
51572 KB |
answer = YES |
4 |
Correct |
35 ms |
51612 KB |
answer = NO |
5 |
Correct |
34 ms |
51524 KB |
answer = YES |
6 |
Correct |
37 ms |
51540 KB |
answer = YES |
7 |
Correct |
37 ms |
51528 KB |
answer = YES |
8 |
Correct |
34 ms |
51532 KB |
answer = YES |
9 |
Correct |
33 ms |
51540 KB |
answer = NO |
10 |
Correct |
36 ms |
51560 KB |
answer = YES |
11 |
Correct |
35 ms |
51652 KB |
answer = YES |
12 |
Correct |
33 ms |
51540 KB |
answer = NO |
13 |
Correct |
36 ms |
51540 KB |
answer = YES |
14 |
Correct |
33 ms |
51540 KB |
answer = YES |
15 |
Correct |
34 ms |
51540 KB |
answer = YES |
16 |
Correct |
36 ms |
51608 KB |
answer = YES |
17 |
Correct |
34 ms |
51604 KB |
answer = YES |
18 |
Correct |
34 ms |
51612 KB |
answer = YES |
19 |
Correct |
35 ms |
51540 KB |
answer = YES |
20 |
Correct |
37 ms |
51508 KB |
answer = YES |
21 |
Correct |
35 ms |
51528 KB |
answer = YES |
22 |
Correct |
36 ms |
51532 KB |
answer = NO |
23 |
Correct |
35 ms |
51604 KB |
answer = NO |
24 |
Correct |
35 ms |
51568 KB |
answer = YES |
25 |
Correct |
33 ms |
51568 KB |
answer = YES |
26 |
Correct |
37 ms |
51612 KB |
answer = YES |
27 |
Correct |
35 ms |
51660 KB |
answer = YES |
28 |
Correct |
35 ms |
51540 KB |
answer = YES |
29 |
Correct |
37 ms |
51616 KB |
answer = YES |
30 |
Correct |
34 ms |
51624 KB |
answer = NO |
31 |
Incorrect |
35 ms |
51568 KB |
participant answer is larger than the answer of jury |
32 |
Halted |
0 ms |
0 KB |
- |