Submission #1020136

# Submission time Handle Problem Language Result Execution time Memory
1020136 2024-07-11T15:28:17 Z Fatonim Graph (BOI20_graph) C++17
0 / 100
2 ms 4956 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 rev(x) (reverse(all(x)))
// bits
#define popcount(n) __builtin_popcountll(n)
#define clz(n) __builtin_clzll(n)
// 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> bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template <class T> bool 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 = 2e5 + 7;
/////////////////////////solve/////////////////////////

map <pi, int> e;
vpi g[maxn];
bool used[maxn];

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

    V<pair<int, ld>> x(n, {0, 0});

    bool good = 1;
    for (int i = 0; i < m; ++i) {
        int v, u, c;
        cin >> v >> u >> c;
        --v; --u;
        if (v > u) swap(v, u);
        if (e[{v, u}] != 0 && e[{v, u}] != c) good = 0;
        e[{v, u}] = c;

        g[v].push_back({u, c});
        g[u].push_back({v, c});
    }

    vi t;
    auto fill_val = [&](ld val) {
        for (auto v : t) {
            x[v].second += x[v].first * val;
            x[v].first = 0;
        }
    };

    function<void(int)> dfs = [&](int v) {
        used[v] = 1;
        t.push_back(v);
        for (auto& [u, c] : g[v]) {
            if (!good) return;

            pair<int, ld> xu = {-x[v].first, c - x[v].second};
            if (!used[u]) {
                x[u] = xu;
                dfs(u);
            }
            else {
                if (x[u] == xu) continue;
                ld a = x[u].first - xu.first;
                ld b = xu.second - x[u].second;
                if (a == 0) good = 0;
                else {
                    ld val = b / a;
                    fill_val(val);
                }
            }
        }
    };

    for (int i = 0; i < n; ++i) {
        if (used[i]) continue;
        x[i] = {1, 0};

        dfs(i);
        dbg(t);
        dbg(x);
        if (x[i].first != 0) {
            vd m;
            for (auto v : t) {
                if (x[v].first == 1) m.push_back(x[v].second);
                else m.push_back(-x[v].second);
            }
            sort(all(m));
            fill_val(m[sz(m) / 2]);
        }

        t.clear();
    }

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

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

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 4956 KB answer = YES
2 Correct 2 ms 4956 KB answer = YES
3 Correct 2 ms 4956 KB answer = YES
4 Correct 2 ms 4952 KB answer = NO
5 Correct 2 ms 4956 KB answer = YES
6 Incorrect 2 ms 4956 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB answer = YES
2 Correct 2 ms 4956 KB answer = YES
3 Correct 2 ms 4956 KB answer = YES
4 Correct 2 ms 4952 KB answer = NO
5 Correct 2 ms 4956 KB answer = YES
6 Incorrect 2 ms 4956 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB answer = YES
2 Correct 2 ms 4956 KB answer = YES
3 Correct 2 ms 4956 KB answer = YES
4 Correct 2 ms 4952 KB answer = NO
5 Correct 2 ms 4956 KB answer = YES
6 Incorrect 2 ms 4956 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB answer = YES
2 Correct 2 ms 4956 KB answer = YES
3 Correct 2 ms 4956 KB answer = YES
4 Correct 2 ms 4952 KB answer = NO
5 Correct 2 ms 4956 KB answer = YES
6 Incorrect 2 ms 4956 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB answer = YES
2 Correct 2 ms 4956 KB answer = YES
3 Correct 2 ms 4956 KB answer = YES
4 Correct 2 ms 4952 KB answer = NO
5 Correct 2 ms 4956 KB answer = YES
6 Incorrect 2 ms 4956 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -