# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
745226 | MilosMilutinovic | Graph (BOI20_graph) | C++14 | 3 ms | 5076 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |