# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
745226 | 2023-05-19T15:10:08 Z | MilosMilutinovic | Graph (BOI20_graph) | C++14 | 3 ms | 5076 KB |
#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 & ((w - delta[y]) == delta[x])); } else { found = true; val = (w - delta[x] - delta[y]) * 1.0 / (coeff[y] + coeff[x]); } continue; } coeff[y] = -coeff[x]; delta[y] = w - delta[x]; 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5076 KB | answer = YES |
2 | Correct | 3 ms | 4948 KB | answer = YES |
3 | Correct | 3 ms | 4948 KB | answer = YES |
4 | Correct | 3 ms | 4948 KB | answer = NO |
5 | Correct | 3 ms | 4948 KB | answer = YES |
6 | Incorrect | 3 ms | 4948 KB | participant answer is larger than the answer of jury |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5076 KB | answer = YES |
2 | Correct | 3 ms | 4948 KB | answer = YES |
3 | Correct | 3 ms | 4948 KB | answer = YES |
4 | Correct | 3 ms | 4948 KB | answer = NO |
5 | Correct | 3 ms | 4948 KB | answer = YES |
6 | Incorrect | 3 ms | 4948 KB | participant answer is larger than the answer of jury |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5076 KB | answer = YES |
2 | Correct | 3 ms | 4948 KB | answer = YES |
3 | Correct | 3 ms | 4948 KB | answer = YES |
4 | Correct | 3 ms | 4948 KB | answer = NO |
5 | Correct | 3 ms | 4948 KB | answer = YES |
6 | Incorrect | 3 ms | 4948 KB | participant answer is larger than the answer of jury |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5076 KB | answer = YES |
2 | Correct | 3 ms | 4948 KB | answer = YES |
3 | Correct | 3 ms | 4948 KB | answer = YES |
4 | Correct | 3 ms | 4948 KB | answer = NO |
5 | Correct | 3 ms | 4948 KB | answer = YES |
6 | Incorrect | 3 ms | 4948 KB | participant answer is larger than the answer of jury |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5076 KB | answer = YES |
2 | Correct | 3 ms | 4948 KB | answer = YES |
3 | Correct | 3 ms | 4948 KB | answer = YES |
4 | Correct | 3 ms | 4948 KB | answer = NO |
5 | Correct | 3 ms | 4948 KB | answer = YES |
6 | Incorrect | 3 ms | 4948 KB | participant answer is larger than the answer of jury |
7 | Halted | 0 ms | 0 KB | - |