Submission #994525

# Submission time Handle Problem Language Result Execution time Memory
994525 2024-06-07T18:47:01 Z Fatonim Graph (BOI20_graph) C++17
0 / 100
2 ms 6544 KB
// "We create our own demons."
#include <bits/stdc++.h>

using namespace std;

#ifdef ONPC
    #include "debug.h"
#else
    #define dbg(...)
#endif

#define int long long
#define ll long long
#define ld long double
#define pi pair<int, int>
// vector
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define maxel(x) (*max_element(all(x)))
#define minel(x) (*min_element(all(x)))
#define maxpos(x) (max_element(all(x)) - x.begin())
#define minpos(x) (min_element(all(x)) - x.begin())
#define srt(x) (sort(all(x)))
#define rev(x) (reverse(all(x)))
// bitwise operations
#define cnt_bit(n) __builtin_popcountll(n)
#define low_bit(n) ((n) & (-(n)))
#define bit(n, i) (((n) >> (i)) & 1)
#define set_bit(n, i) ((n) | (1LL << (i)))
#define reset_bit(n, i) ((n) & ~(1LL << (i)))
#define flip_bit(n, i) ((n) ^ (1LL << (i)))
// math
#define sqr(n) ((n) * (n))
#define divup(a, b) (((a) + (b)-1) / (b))
// ostream
#define Fixed(a) cout << fixed << setprecision(12) << a;

template <class T> void chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template <class T> void chmax(T& a, const T& b) { return b > a ? a = b, 1 : 0; }

template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> using max_queue = priority_queue<T, vector<T>, less<T>>;

template <class T> using V = vector<T>;
using vi = V<int>;
using vd = V<ld>;
using vb = V<bool>;
using vpi = V<pi>;
using vvi = V<vi>;
using vvb = V<vb>;

const int mod = 1e9 + 7; // 998244353 1e9 + 7
const ll inf = (int)(1e18) + 7;
const int inf_s = 1e9 + 7;
const ld eps = 1e-9;

const int B = 32;
const int N = 1000 + 3;
const int logn = 20;
const int maxn = 1e5 + 7;
/////////////////////////solve/////////////////////////

vpi g[maxn];
pi a[maxn];
ld ans[maxn];
int used[maxn];
vi t;

void dfs(int v) {
    t.push_back(v);
    used[v] = 1;
    for (auto& [u, c] : g[v]) {
        if (!used[u]) {
            a[u] = {c - a[v].first, -a[v].second};
            dfs(u);
        }
    }
}

void solve() {
    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; ++i) {
        int v, u, c;
        cin >> v >> u >> c;
        --v; --u;
        g[v].push_back({u, c});
        g[u].push_back({v, c});
    }

    for (int i = 0; i < n; ++i) {
        if (used[i]) continue;
        a[i] = {0, 1};
        t.clear();
        dfs(i);
        ld rt = 0;
        bool bad = 0, was = 0;
        for (auto v : t) {
            for (auto& [u, c] : g[v]) {
                ld q1 = a[v].second + a[u].second;
                ld q2 = a[v].first + a[u].first;
                if (q1 == 0) {
                    if (q2 != c) bad = 1;
                    continue;
                }
                ld nrt = (c - q2) / q1;
                dbg(i, nrt, v, u);
                if (was && rt == nrt) continue;
                else if (!was) {
                    was = 1;
                    rt = nrt;
                }
                else bad = 1;
            }
        }

        if (bad) {
            cout << "NO\n";
            return;
        }

        dbg(i, was, rt);
        if (!was) {
            int sum = 0;
            for (auto v : t) {
                sum += a[v].second;
            }
            if (sum != 0) {
                cout << "sum\n";
                return;
            }
            rt = 0;
        }
        for (auto v : t) {
            ans[v] = a[v].first + (ld)(a[v].second) * rt;
        }
    }

    cout << "YES\n";
    for (int i = 0; i < n; ++i) {
        cout << ans[i] << " ";
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

#ifdef ONPC
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif

    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; ++i) {
#ifdef ONPC
        cerr << "===========" << i << "===========" << '\n';
#endif
        solve();
    }

#ifdef ONPC
    cerr << endl << "Time " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6544 KB answer = YES
2 Correct 1 ms 6492 KB answer = YES
3 Incorrect 1 ms 4444 KB Expected YES or NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6544 KB answer = YES
2 Correct 1 ms 6492 KB answer = YES
3 Incorrect 1 ms 4444 KB Expected YES or NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6544 KB answer = YES
2 Correct 1 ms 6492 KB answer = YES
3 Incorrect 1 ms 4444 KB Expected YES or NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6544 KB answer = YES
2 Correct 1 ms 6492 KB answer = YES
3 Incorrect 1 ms 4444 KB Expected YES or NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6544 KB answer = YES
2 Correct 1 ms 6492 KB answer = YES
3 Incorrect 1 ms 4444 KB Expected YES or NO
4 Halted 0 ms 0 KB -