Submission #1052166

# Submission time Handle Problem Language Result Execution time Memory
1052166 2024-08-10T12:13:05 Z duckindog Graph (BOI20_graph) C++17
0 / 100
2 ms 3164 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 100'000 + 10,
          MAX = 1'000'000'000;
int n, m;
vector<pair<int, int>> ad[N];
int a[N];

int32_t main() { 
  cin.tie(0)->sync_with_stdio(0);

  cin >> n >> m;
  for (int i = 1; i <= m; ++i) { 
    int u, v, w; cin >> u >> v >> w;
    w *= 10;
    ad[u].push_back({v, w});
    ad[v].push_back({u, w});
  }

  auto cal = [&](int x) { 
    memset(a, -1, sizeof a);
    a[1] = x;
    queue<int> q({1});
    int ret = 0;
    while (q.size()) { 
      auto u = q.front(); q.pop();
      ret += abs(a[u]);
      for (const auto& [v, w] : ad[u]) { 
        if (a[v] == -1) { 
          a[v] = w - a[u];
          q.push(v);
        }
        if (w - a[u] != a[v]) return MAX;
      }
    }
    return ret;
  };
  int st = -1;
  int answer = MAX;
  for (int x = -100; x <= 300; ++x) { 
    int value = cal(x);
    if (answer > value) { 
      answer = value;
      st = x;
    }
  }

  if (st == -1) { cout << "NO" << "\n"; return 0; }
  cal(st);
  cout << "YES" << "\n";
  for (int i = 1; i <= n; ++i) {
    if (a[i] < 0) cout << '-' << a[i] / 10 << "." << abs(a[i]) % 10 << " ";
    else cout << a[i] / 10 << "." << abs(a[i]) % 10 << " ";  
  }
  cout << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3164 KB answer = YES
2 Correct 2 ms 3164 KB answer = YES
3 Correct 2 ms 3164 KB answer = YES
4 Correct 2 ms 3164 KB answer = NO
5 Incorrect 2 ms 3164 KB Sum of endpoints for edge (5; 3) differs from the expected value 2.
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3164 KB answer = YES
2 Correct 2 ms 3164 KB answer = YES
3 Correct 2 ms 3164 KB answer = YES
4 Correct 2 ms 3164 KB answer = NO
5 Incorrect 2 ms 3164 KB Sum of endpoints for edge (5; 3) differs from the expected value 2.
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3164 KB answer = YES
2 Correct 2 ms 3164 KB answer = YES
3 Correct 2 ms 3164 KB answer = YES
4 Correct 2 ms 3164 KB answer = NO
5 Incorrect 2 ms 3164 KB Sum of endpoints for edge (5; 3) differs from the expected value 2.
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3164 KB answer = YES
2 Correct 2 ms 3164 KB answer = YES
3 Correct 2 ms 3164 KB answer = YES
4 Correct 2 ms 3164 KB answer = NO
5 Incorrect 2 ms 3164 KB Sum of endpoints for edge (5; 3) differs from the expected value 2.
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3164 KB answer = YES
2 Correct 2 ms 3164 KB answer = YES
3 Correct 2 ms 3164 KB answer = YES
4 Correct 2 ms 3164 KB answer = NO
5 Incorrect 2 ms 3164 KB Sum of endpoints for edge (5; 3) differs from the expected value 2.
6 Halted 0 ms 0 KB -