# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
557060 |
2022-05-04T16:47:55 Z |
proma |
Graph (BOI20_graph) |
C++17 |
|
2 ms |
2684 KB |
#include <bits/stdc++.h>
//#define int long long
#define endl "\n"
#define see(x) cout<<#x<<"="<<x<<"\n";
using namespace std;
const int N = 1e5+5;
//const int INF = 1e9;
int n, m, used[N], val[N], s[N], flag;
vector <pair <int, int>> g[N];
vector <int> visited;
double x, res[N];
void dfs(int v, int p = 0) {
used[v] = 1;
visited.push_back(v);
for (auto i: g[v]) {
if (i.first == p) continue;
if (used[i.first] and s[i.first] == s[v] and !flag) {
x = (i.second - val[i.first] - val[v]) / 2.0;
flag = 1;
}
else if (!used[i.first]) {
s[i.first] = -s[v];
val[i.first] = i.second - val[v];
dfs(i.first, v);
}
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
/*
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
*/
cin >> n >> m;
for (int i = 0; i < m; i ++) {
int u, v, w;
cin >> u >> v >> w;
g[u].push_back({v, w});
g[v].push_back({u, w});
}
for (int i = 1; i <= n; i ++) {
if (!used[i]) {
flag = 0;
s[i] = 1;
val[i] = 0;
visited.clear();
dfs(i);
if (!flag) {
vector <int> v;
for (auto i: visited) {
v.push_back(val[i] * (-s[i]));
}
sort(v.begin(), v.end());
x = v[int(v.size())/2];
}
for (auto i: visited) {
res[i] = s[i] * x + val[i];
}
}
}
for (int i = 1; i <= n; i ++) {
for (auto j: g[i]) {
if (res[i] + res[j.first] != j.second) {
cout << "NO\n";
return 0;
}
}
}
cout << "YES\n";
for (int i = 1; i <= n; i ++) {
cout << res[i] << " ";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2684 KB |
answer = YES |
2 |
Correct |
1 ms |
2644 KB |
answer = YES |
3 |
Correct |
1 ms |
2644 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
1 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
1 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2644 KB |
answer = NO |
10 |
Correct |
1 ms |
2644 KB |
answer = YES |
11 |
Incorrect |
1 ms |
2644 KB |
jury has the better answer: jans = YES, pans = NO |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2684 KB |
answer = YES |
2 |
Correct |
1 ms |
2644 KB |
answer = YES |
3 |
Correct |
1 ms |
2644 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
1 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
1 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2644 KB |
answer = NO |
10 |
Correct |
1 ms |
2644 KB |
answer = YES |
11 |
Incorrect |
1 ms |
2644 KB |
jury has the better answer: jans = YES, pans = NO |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2684 KB |
answer = YES |
2 |
Correct |
1 ms |
2644 KB |
answer = YES |
3 |
Correct |
1 ms |
2644 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
1 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
1 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2644 KB |
answer = NO |
10 |
Correct |
1 ms |
2644 KB |
answer = YES |
11 |
Incorrect |
1 ms |
2644 KB |
jury has the better answer: jans = YES, pans = NO |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2684 KB |
answer = YES |
2 |
Correct |
1 ms |
2644 KB |
answer = YES |
3 |
Correct |
1 ms |
2644 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
1 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
1 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2644 KB |
answer = NO |
10 |
Correct |
1 ms |
2644 KB |
answer = YES |
11 |
Incorrect |
1 ms |
2644 KB |
jury has the better answer: jans = YES, pans = NO |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2684 KB |
answer = YES |
2 |
Correct |
1 ms |
2644 KB |
answer = YES |
3 |
Correct |
1 ms |
2644 KB |
answer = YES |
4 |
Correct |
1 ms |
2644 KB |
answer = NO |
5 |
Correct |
1 ms |
2644 KB |
answer = YES |
6 |
Correct |
1 ms |
2644 KB |
answer = YES |
7 |
Correct |
2 ms |
2644 KB |
answer = YES |
8 |
Correct |
1 ms |
2644 KB |
answer = YES |
9 |
Correct |
1 ms |
2644 KB |
answer = NO |
10 |
Correct |
1 ms |
2644 KB |
answer = YES |
11 |
Incorrect |
1 ms |
2644 KB |
jury has the better answer: jans = YES, pans = NO |
12 |
Halted |
0 ms |
0 KB |
- |