# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
342903 | mjhmjh1104 | Graph (BOI20_graph) | C++14 | 2 ms | 2668 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int n, m;
int a[100006], c[100006];
bool visited[100006];
vector<pair<int, int>> adj[100006];
vector<double> v;
void dfs(int x, int prev = -1) {
visited[x] = true;
for (auto &i: adj[x]) if (i.first != prev) {
if (!visited[i.first]) {
a[i.first] = -a[x];
c[i.first] = i.second - c[x];
dfs(i.first, x);
} else {
if (a[i.first] + a[x] == 0) {
if (c[i.first] + c[x] != i.second) {
puts("NO");
exit(0);
}
} else v.push_back((double)(i.second - c[i.first] - c[x]) / (a[i.first] + a[x]));
}
}
}
int main() {
scanf("%d%d", &n, &m);
while (m--) {
int u, v, c;
scanf("%d%d%d", &u, &v, &c);
u--, v--;
adj[u].push_back({ v, c });
adj[v].push_back({ u, c });
}
a[0] = 1, c[0] = 0;
dfs(0);
if (v.empty()) {
puts("YES");
for (int i = 0; i < n; i++) printf("%.8f ", (double)c[i]);
} else {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
if (v.size() != 1) puts("NO");
else {
puts("YES");
for (int i = 0; i < n; i++) printf("%.8f ", a[i] * v[0] + c[i]);
}
}
}
컴파일 시 표준 에러 (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... |