답안 #675600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
675600 2022-12-27T13:51:51 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;
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 = 5;
        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 == 5) pot = x;
                else if (pot != x) {
                    cout << "NO\n";
                    return 0;
                }
            }
        }
        if (pot == 5) pot = 0;
        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:52: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]
   52 |             for (int k = 1; k < r[j].size(); k++) {
      |                             ~~^~~~~~~~~~~~~
Graph.cpp:47:13: warning: unused variable 'ok' [-Wunused-variable]
   47 |         int ok = 1;
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB answer = YES
2 Correct 1 ms 324 KB answer = YES
3 Correct 1 ms 212 KB answer = YES
4 Correct 1 ms 316 KB answer = NO
5 Correct 1 ms 212 KB answer = YES
6 Incorrect 1 ms 212 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB answer = YES
2 Correct 1 ms 324 KB answer = YES
3 Correct 1 ms 212 KB answer = YES
4 Correct 1 ms 316 KB answer = NO
5 Correct 1 ms 212 KB answer = YES
6 Incorrect 1 ms 212 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB answer = YES
2 Correct 1 ms 324 KB answer = YES
3 Correct 1 ms 212 KB answer = YES
4 Correct 1 ms 316 KB answer = NO
5 Correct 1 ms 212 KB answer = YES
6 Incorrect 1 ms 212 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB answer = YES
2 Correct 1 ms 324 KB answer = YES
3 Correct 1 ms 212 KB answer = YES
4 Correct 1 ms 316 KB answer = NO
5 Correct 1 ms 212 KB answer = YES
6 Incorrect 1 ms 212 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB answer = YES
2 Correct 1 ms 324 KB answer = YES
3 Correct 1 ms 212 KB answer = YES
4 Correct 1 ms 316 KB answer = NO
5 Correct 1 ms 212 KB answer = YES
6 Incorrect 1 ms 212 KB participant answer is larger than the answer of jury
7 Halted 0 ms 0 KB -