Submission #745161

# Submission time Handle Problem Language Result Execution time Memory
745161 2023-05-19T13:26:01 Z MilosMilutinovic Graph (BOI20_graph) C++14
0 / 100
2 ms 4948 KB
/* todo */
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, m, coeff[N], delta[N];
double ans[N], val;
vector<pair<int, int>> g[N];
vector<int> comp;
bool ok = true, found, was[N];
void dfs(int x) {
    was[x] = true;
    comp.push_back(x);
    for (auto& p : g[x]) {
        int y = p.first;
        int w = p.second;
        if (was[y]) {
            if (coeff[y] == coeff[x]) {
                ok = (ok & (delta[y] == delta[y]));
            } else {
                found = true;
                val = -(delta[x] * coeff[x] + delta[y] * coeff[y]) / 2;
            }
            continue;
        }
        coeff[y] = 1 - coeff[x];
        delta[y] = w - delta[y];
        dfs(y);
    }
}
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        g[a].emplace_back(b, c);
        g[b].emplace_back(a, c);
    }
    for (int i = 1; i <= n; i++) if (!was[i]) {
        coeff[i] = 1;
        delta[i] = 0;
        comp.clear();
        found = false;
        dfs(i);
        if (!ok) break;
        if (found) {
            for (int x : comp) ans[x] = val * coeff[x] + delta[x];
        } else {
            vector<int> f;
            for (int x : comp) f.push_back(delta[x] * coeff[x]);
            sort(f.begin(), f.end());
            val = f[(int) f.size() / 2];
            for (int x : comp) ans[x] = val * coeff[x] + delta[x];
        }
    }
    for (int i = 1; i <= n; i++) {
        for (auto& p : g[i]) {
            if (ans[i] + ans[p.first] != p.second * 1.0) ok = false;
        }
    }
    if (!ok) { printf("NO"); return 0; }
    printf("YES\n");
    for (int i = 1; i <= n; i++) printf("%0.5lf ", ans[i]);
    return 0;
}

Compilation message

Graph.cpp: In function 'void dfs(int)':
Graph.cpp:18:38: warning: self-comparison always evaluates to true [-Wtautological-compare]
   18 |                 ok = (ok & (delta[y] == delta[y]));
      |                             ~~~~~~~~ ^~ ~~~~~~~~
Graph.cpp: In function 'int main()':
Graph.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
Graph.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         scanf("%d%d%d", &a, &b, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB jury has the better answer: jans = YES, pans = NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB jury has the better answer: jans = YES, pans = NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB jury has the better answer: jans = YES, pans = NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB jury has the better answer: jans = YES, pans = NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB jury has the better answer: jans = YES, pans = NO
2 Halted 0 ms 0 KB -