답안 #650612

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
650612 2022-10-14T09:31:25 Z welleyth Graph (BOI20_graph) C++17
17 / 100
21 ms 3604 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)1e5+11;
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;
}

int ans[N];
int mn = INF;

int try_start(int 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)
        return INF;
    int sum = 0;
    for(auto& v : component){
        sum += abs(val[v]);
    }
    if(sum < mn){
        mn = sum;
        for(auto& v : component)
            ans[v] = val[v];
    }
    return sum;
}

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;
    memset(ans,0,sizeof ans);

    for(int i = 1; i <= n; i++){
        if(!U[i]){
            component.clear();
            dfs2(i);
            mn = INF;
//            for(int j = -100; j <= 100; j++) try_start(j);
//            for(int j = -10; j <= 10; j++) try_start(j);
            for(int j = -10; j <= 10; j++){
                try_start(j);
                int m = j, mx = j;
                for(auto& v : component){
                    m = min(m,val[v]);
                    mx = max(mx,val[v]);
                }
                int mid = (mn + mx) / 2;
                for(int t = mid-10; t <= mid+10; t++){
                    try_start(t);
                }
            }
//            for(int j = l; j <= r; j++) try_start(j);
            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;
}
/**
**/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB answer = YES
2 Correct 2 ms 3412 KB answer = YES
3 Correct 2 ms 3412 KB answer = YES
4 Correct 2 ms 3412 KB answer = NO
5 Correct 2 ms 3412 KB answer = YES
6 Correct 2 ms 3412 KB answer = YES
7 Correct 2 ms 3412 KB answer = YES
8 Correct 2 ms 3412 KB answer = YES
9 Correct 2 ms 3412 KB answer = NO
10 Correct 2 ms 3412 KB answer = YES
11 Correct 2 ms 3412 KB answer = YES
12 Correct 2 ms 3412 KB answer = NO
13 Correct 2 ms 3412 KB answer = YES
14 Correct 2 ms 3412 KB answer = YES
15 Correct 2 ms 3412 KB answer = YES
16 Correct 2 ms 3412 KB answer = YES
17 Correct 2 ms 3412 KB answer = YES
18 Correct 2 ms 3412 KB answer = YES
19 Correct 2 ms 3412 KB answer = YES
20 Correct 2 ms 3412 KB answer = YES
21 Correct 2 ms 3412 KB answer = YES
22 Correct 2 ms 3412 KB answer = NO
23 Correct 2 ms 3412 KB answer = NO
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB answer = YES
2 Correct 2 ms 3412 KB answer = YES
3 Correct 2 ms 3412 KB answer = YES
4 Correct 2 ms 3412 KB answer = NO
5 Correct 2 ms 3412 KB answer = YES
6 Correct 2 ms 3412 KB answer = YES
7 Correct 2 ms 3412 KB answer = YES
8 Correct 2 ms 3412 KB answer = YES
9 Correct 2 ms 3412 KB answer = NO
10 Correct 2 ms 3412 KB answer = YES
11 Correct 2 ms 3412 KB answer = YES
12 Correct 2 ms 3412 KB answer = NO
13 Correct 2 ms 3412 KB answer = YES
14 Correct 2 ms 3412 KB answer = YES
15 Correct 2 ms 3412 KB answer = YES
16 Correct 2 ms 3412 KB answer = YES
17 Correct 2 ms 3412 KB answer = YES
18 Correct 2 ms 3412 KB answer = YES
19 Correct 2 ms 3412 KB answer = YES
20 Correct 2 ms 3412 KB answer = YES
21 Correct 2 ms 3412 KB answer = YES
22 Correct 2 ms 3412 KB answer = NO
23 Correct 2 ms 3412 KB answer = NO
24 Correct 6 ms 3412 KB answer = YES
25 Correct 5 ms 3412 KB answer = YES
26 Correct 4 ms 3412 KB answer = YES
27 Correct 2 ms 3412 KB answer = YES
28 Correct 3 ms 3412 KB answer = YES
29 Correct 5 ms 3412 KB answer = YES
30 Correct 3 ms 3412 KB answer = NO
31 Correct 4 ms 3412 KB answer = YES
32 Correct 3 ms 3412 KB answer = YES
33 Correct 4 ms 3412 KB answer = YES
34 Correct 3 ms 3412 KB answer = YES
35 Correct 5 ms 3412 KB answer = YES
36 Correct 4 ms 3464 KB answer = YES
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB answer = YES
2 Correct 2 ms 3412 KB answer = YES
3 Correct 2 ms 3412 KB answer = YES
4 Correct 2 ms 3412 KB answer = NO
5 Correct 2 ms 3412 KB answer = YES
6 Correct 2 ms 3412 KB answer = YES
7 Correct 2 ms 3412 KB answer = YES
8 Correct 2 ms 3412 KB answer = YES
9 Correct 2 ms 3412 KB answer = NO
10 Correct 2 ms 3412 KB answer = YES
11 Correct 2 ms 3412 KB answer = YES
12 Correct 2 ms 3412 KB answer = NO
13 Correct 2 ms 3412 KB answer = YES
14 Correct 2 ms 3412 KB answer = YES
15 Correct 2 ms 3412 KB answer = YES
16 Correct 2 ms 3412 KB answer = YES
17 Correct 2 ms 3412 KB answer = YES
18 Correct 2 ms 3412 KB answer = YES
19 Correct 2 ms 3412 KB answer = YES
20 Correct 2 ms 3412 KB answer = YES
21 Correct 2 ms 3412 KB answer = YES
22 Correct 2 ms 3412 KB answer = NO
23 Correct 2 ms 3412 KB answer = NO
24 Correct 6 ms 3412 KB answer = YES
25 Correct 5 ms 3412 KB answer = YES
26 Correct 4 ms 3412 KB answer = YES
27 Correct 2 ms 3412 KB answer = YES
28 Correct 3 ms 3412 KB answer = YES
29 Correct 5 ms 3412 KB answer = YES
30 Correct 3 ms 3412 KB answer = NO
31 Correct 4 ms 3412 KB answer = YES
32 Correct 3 ms 3412 KB answer = YES
33 Correct 4 ms 3412 KB answer = YES
34 Correct 3 ms 3412 KB answer = YES
35 Correct 5 ms 3412 KB answer = YES
36 Correct 4 ms 3464 KB answer = YES
37 Correct 8 ms 3412 KB answer = YES
38 Correct 4 ms 3484 KB answer = YES
39 Correct 19 ms 3412 KB answer = YES
40 Incorrect 21 ms 3604 KB jury has the better answer: jans = YES, pans = NO
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB answer = YES
2 Correct 2 ms 3412 KB answer = YES
3 Correct 2 ms 3412 KB answer = YES
4 Correct 2 ms 3412 KB answer = NO
5 Correct 2 ms 3412 KB answer = YES
6 Correct 2 ms 3412 KB answer = YES
7 Correct 2 ms 3412 KB answer = YES
8 Correct 2 ms 3412 KB answer = YES
9 Correct 2 ms 3412 KB answer = NO
10 Correct 2 ms 3412 KB answer = YES
11 Correct 2 ms 3412 KB answer = YES
12 Correct 2 ms 3412 KB answer = NO
13 Correct 2 ms 3412 KB answer = YES
14 Correct 2 ms 3412 KB answer = YES
15 Correct 2 ms 3412 KB answer = YES
16 Correct 2 ms 3412 KB answer = YES
17 Correct 2 ms 3412 KB answer = YES
18 Correct 2 ms 3412 KB answer = YES
19 Correct 2 ms 3412 KB answer = YES
20 Correct 2 ms 3412 KB answer = YES
21 Correct 2 ms 3412 KB answer = YES
22 Correct 2 ms 3412 KB answer = NO
23 Correct 2 ms 3412 KB answer = NO
24 Correct 6 ms 3412 KB answer = YES
25 Correct 5 ms 3412 KB answer = YES
26 Correct 4 ms 3412 KB answer = YES
27 Correct 2 ms 3412 KB answer = YES
28 Correct 3 ms 3412 KB answer = YES
29 Correct 5 ms 3412 KB answer = YES
30 Correct 3 ms 3412 KB answer = NO
31 Correct 4 ms 3412 KB answer = YES
32 Correct 3 ms 3412 KB answer = YES
33 Correct 4 ms 3412 KB answer = YES
34 Correct 3 ms 3412 KB answer = YES
35 Correct 5 ms 3412 KB answer = YES
36 Correct 4 ms 3464 KB answer = YES
37 Correct 8 ms 3412 KB answer = YES
38 Correct 4 ms 3484 KB answer = YES
39 Correct 19 ms 3412 KB answer = YES
40 Incorrect 21 ms 3604 KB jury has the better answer: jans = YES, pans = NO
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB answer = YES
2 Correct 2 ms 3412 KB answer = YES
3 Correct 2 ms 3412 KB answer = YES
4 Correct 2 ms 3412 KB answer = NO
5 Correct 2 ms 3412 KB answer = YES
6 Correct 2 ms 3412 KB answer = YES
7 Correct 2 ms 3412 KB answer = YES
8 Correct 2 ms 3412 KB answer = YES
9 Correct 2 ms 3412 KB answer = NO
10 Correct 2 ms 3412 KB answer = YES
11 Correct 2 ms 3412 KB answer = YES
12 Correct 2 ms 3412 KB answer = NO
13 Correct 2 ms 3412 KB answer = YES
14 Correct 2 ms 3412 KB answer = YES
15 Correct 2 ms 3412 KB answer = YES
16 Correct 2 ms 3412 KB answer = YES
17 Correct 2 ms 3412 KB answer = YES
18 Correct 2 ms 3412 KB answer = YES
19 Correct 2 ms 3412 KB answer = YES
20 Correct 2 ms 3412 KB answer = YES
21 Correct 2 ms 3412 KB answer = YES
22 Correct 2 ms 3412 KB answer = NO
23 Correct 2 ms 3412 KB answer = NO
24 Correct 6 ms 3412 KB answer = YES
25 Correct 5 ms 3412 KB answer = YES
26 Correct 4 ms 3412 KB answer = YES
27 Correct 2 ms 3412 KB answer = YES
28 Correct 3 ms 3412 KB answer = YES
29 Correct 5 ms 3412 KB answer = YES
30 Correct 3 ms 3412 KB answer = NO
31 Correct 4 ms 3412 KB answer = YES
32 Correct 3 ms 3412 KB answer = YES
33 Correct 4 ms 3412 KB answer = YES
34 Correct 3 ms 3412 KB answer = YES
35 Correct 5 ms 3412 KB answer = YES
36 Correct 4 ms 3464 KB answer = YES
37 Correct 8 ms 3412 KB answer = YES
38 Correct 4 ms 3484 KB answer = YES
39 Correct 19 ms 3412 KB answer = YES
40 Incorrect 21 ms 3604 KB jury has the better answer: jans = YES, pans = NO
41 Halted 0 ms 0 KB -