Submission #862672

# Submission time Handle Problem Language Result Execution time Memory
862672 2023-10-18T19:41:17 Z faruk Graph (BOI20_graph) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
#define mp make_pair
#define all(a) a.begin(), a.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, double> pid;

const double DINF = 1e18;
const ll INF = 1e18;
const double EPS = 1e-3;

vector<vector<pid> > graph;
vector<double> val;

double sum;
bool ok = false;
void dfs1(int curr) {
    if (!ok)
        return;
    for (auto &[a, d] : graph[curr]) {
        double new_v = d - val[curr];
        if (val[a] != DINF and abs(val[a] - new_v) > EPS)
        {
            ok = false;
            return;
        }
        if (val[a] != DINF)
            continue;
        val[a] = new_v; sum += abs(new_v);
        dfs1(a);
    }
}

vector<bool> visited;
vector<vector<int> > cmp;
void dfs2(int curr, vector<int> &cmp) {
    cmp.push_back(curr); visited[curr] = true;
    for (auto &[a, d] : graph[curr])
        if (!visited[a])
            dfs2(a, cmp);
}

ll tryy(int idx, double v, vector<int> &comp) {
    for (int a : comp)
        val[a] = INF;
    val[idx] = v;
    sum = abs(v), ok = true;
    dfs1(idx);
    if (!ok)
        return INF;
    return sum;
}

pair<ll, double> get_for_cmp(int guy) {
    int cmp_size = cmp[guy].size(); pair<ll, double> mini(INF, 0);
    for (double val = -cmp_size*10; val <= cmp_size*10; val += 0.5)
        mini = min(mini, {tryy(guy, val, cmp[guy]), val});
    return mini;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >>n >> m;
    graph.resize(n+1);
    val.resize(n+1);
    visited.resize(n+1);
    cmp.resize(n+1);

    for (int i = 0; i < m; i++) {
        int f, t, w;
        cin >> f >> t >> w;
        graph[f].push_back({t, w});
        graph[t].push_back({f, w});
    }
    // init_cmp
    for (int i = 1; i <= n; i++) {
        if (!visited[i]) {
            dfs2(i, cmp[i]);

            auto v = get_for_cmp(i);
            if (v.first == INF)
            {
                cout <<"NO\n";
                return 0;
            }
            tryy(i, v.second, cmp[i]);
        }
    }

    
    cout <<"YES\n";
    for (int i = 1; i <= n; i++)
        cout << val[i] << " ";
    cout << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Incorrect 0 ms 348 KB participant answer is larger than the answer of jury
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Incorrect 0 ms 348 KB participant answer is larger than the answer of jury
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Incorrect 0 ms 348 KB participant answer is larger than the answer of jury
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Incorrect 0 ms 348 KB participant answer is larger than the answer of jury
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB answer = YES
2 Correct 0 ms 348 KB answer = YES
3 Correct 0 ms 348 KB answer = YES
4 Correct 0 ms 348 KB answer = NO
5 Incorrect 0 ms 348 KB participant answer is larger than the answer of jury
6 Halted 0 ms 0 KB -