Submission #675651

# Submission time Handle Problem Language Result Execution time Memory
675651 2022-12-27T15:43:52 Z stevancv Graph (BOI20_graph) C++14
0 / 100
1 ms 324 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 3e5 + 2;
const int mod = 1e9 + 7;
const double inf = -1e6;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int, int>>> g(n);
    for (int i = 0; i < m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u -= 1; v -= 1;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    vector<int> comp, was(n);
    vector<double> ans(n);
    vector<vector<pair<int, int>>> r(n);
    function<void(int, int, int, int)> Dfs = [&] (int s, int e, int a, int b) {
        was[s] = 1;
        r[s].push_back({a, b});
        comp.push_back(s);
        for (auto u : g[s]) {
            if (u.first == e) continue;
            if (was[u.first] == 0) {
                Dfs(u.first, s, -a, u.second - b);
            }
            else {
                int aa = r[u.first].back().first;
                int bb = r[u.first].back().second;
                r[s].push_back({-aa, u.second - bb});
            }
        }
    };
    for (int i = 0; i < n; i++) {
        if (was[i] == 1) continue;
        Dfs(i, -1, 1, 0);
        int ok = 1;
        double pot = inf;
        for (int j : comp) {
            sort(r[j].begin(), r[j].end());
            r[j].erase(unique(r[j].begin(), r[j].end()), r[j].end());
            for (int k = 1; k < r[j].size(); k++) {
                if (r[j][k].first == r[j][k - 1].first) {
                    cout << "NO\n";
                    return 0;
                }
                double x = (double)(r[j][k].second - r[j][k - 1].second) / (r[j][k - 1].first - r[j][k].first);
                if (pot == inf) pot = x;
                else if (pot != x) {
                    cout << "NO\n";
                    return 0;
                }
            }
        }
        if (pot == inf) {
            vector<pair<int, int>> v;
            for (int j : comp) {
                if (r[j][0].first == 1) v.push_back({r[j][0].second, 1});
                else v.push_back({-r[j][0].second, -1});
            }
            sort(v.begin(), v.end());
            int ind = comp.size() / 2;
            pot = v[ind].first * v[ind].second;
        }
        for (int j : comp) {
            ans[j] = 1.0 * r[j][0].first * pot + r[j][0].second;
        }
        comp.clear();
    }
    cout << "YES\n";
    for (int i = 0; i < n; i++) cout << fixed << showpoint << setprecision(1) << ans[i] << sp;
    return 0;
}

Compilation message

Graph.cpp: In function 'int main()':
Graph.cpp:53:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             for (int k = 1; k < r[j].size(); k++) {
      |                             ~~^~~~~~~~~~~~~
Graph.cpp:48:13: warning: unused variable 'ok' [-Wunused-variable]
   48 |         int ok = 1;
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB answer = YES
2 Correct 0 ms 324 KB answer = YES
3 Correct 1 ms 212 KB answer = YES
4 Correct 1 ms 320 KB answer = NO
5 Correct 0 ms 212 KB answer = YES
6 Incorrect 1 ms 316 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB answer = YES
2 Correct 0 ms 324 KB answer = YES
3 Correct 1 ms 212 KB answer = YES
4 Correct 1 ms 320 KB answer = NO
5 Correct 0 ms 212 KB answer = YES
6 Incorrect 1 ms 316 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB answer = YES
2 Correct 0 ms 324 KB answer = YES
3 Correct 1 ms 212 KB answer = YES
4 Correct 1 ms 320 KB answer = NO
5 Correct 0 ms 212 KB answer = YES
6 Incorrect 1 ms 316 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB answer = YES
2 Correct 0 ms 324 KB answer = YES
3 Correct 1 ms 212 KB answer = YES
4 Correct 1 ms 320 KB answer = NO
5 Correct 0 ms 212 KB answer = YES
6 Incorrect 1 ms 316 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB answer = YES
2 Correct 0 ms 324 KB answer = YES
3 Correct 1 ms 212 KB answer = YES
4 Correct 1 ms 320 KB answer = NO
5 Correct 0 ms 212 KB answer = YES
6 Incorrect 1 ms 316 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -