# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
711416 |
2023-03-16T21:28:06 Z |
sysia |
Graph (BOI20_graph) |
C++17 |
|
1 ms |
212 KB |
//Sylwia Sapkowska
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long
typedef pair<int, int> T;
const int oo = 1e9+7;
void solve(){
int n, m; cin >> n >> m;
vector<vector<T>>g(n+1);
for (int i = 0; i<m; i++) {
int a, b, c; cin >> a >> b >> c;
g[a].emplace_back(b, c);
g[b].emplace_back(a, c);
}
vector<T>poly(n+1);
vector<bool>vis(n+1);
long double ans = (long double)oo;
long double eps = 1e-7;
function<void(int)>dfs = [&](int v){
vis[v] = 1;
for (auto [x, c]: g[v]){
if (!vis[x]){
poly[x].first = -poly[v].first;
poly[x].second = c - poly[v].second;
dfs(x);
} else {
//solve the equation
//curr.first * x + curr.second = poly[x].first * x + poly[x].second
//x (curr.first - poly[x].first) = poly[x].second - curr.second;
T curr = {-poly[v].first, c - poly[v].second};
debug(v, x, curr, poly[x], poly[v]);
if (curr.first == poly[x].first) {
if (curr.second != poly[x].second){
cout << "NO\n";
exit(0);
}
continue;
}
long double now = (long double)(poly[x].second - curr.second)/(long double)(curr.first - poly[x].first);
debug(x, v, now);
if (ans == oo) ans = now;
else {
if (abs(now - ans) > eps){
cout << "NO\n";
exit(0);
}
}
}
}
};
poly[1].first = 1;
dfs(1);
debug(poly);
cout << fixed << setprecision(10);
vector<long double>ret(n+1);
auto solve = [&](long double curr){
vis.assign(n+1, 0);
function<void(int)>restore = [&](int v){
vis[v] = 1;
for (auto [x, c]: g[v]){
if (!vis[x]){
ret[x] = (long double)c - ret[v];
restore(x);
}
}
};
ret[1] = curr;
restore(1);
};
if (ans == oo){
vector<long double>check = {-2.0, -1.0, 0.0, -0.5, 0.5, 1.0, 2.0};
long double mn = oo;
for (auto x: check){
solve(x);
long double s = 0.0;
for (int i = 1; i<=n; i++){
s += (long double)abs(ret[i]);
}
if (s <= mn){
mn = s;
ans = x;
}
}
}
cout << "YES\n";
debug(ans);
solve(ans);
for (int i = 1; i<=n; i++) cout << ret[i] << " ";
cout << "\n";
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
1 ms |
212 KB |
answer = YES |
3 |
Correct |
0 ms |
212 KB |
answer = YES |
4 |
Correct |
0 ms |
212 KB |
answer = NO |
5 |
Incorrect |
0 ms |
212 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 |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
1 ms |
212 KB |
answer = YES |
3 |
Correct |
0 ms |
212 KB |
answer = YES |
4 |
Correct |
0 ms |
212 KB |
answer = NO |
5 |
Incorrect |
0 ms |
212 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 |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
1 ms |
212 KB |
answer = YES |
3 |
Correct |
0 ms |
212 KB |
answer = YES |
4 |
Correct |
0 ms |
212 KB |
answer = NO |
5 |
Incorrect |
0 ms |
212 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 |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
1 ms |
212 KB |
answer = YES |
3 |
Correct |
0 ms |
212 KB |
answer = YES |
4 |
Correct |
0 ms |
212 KB |
answer = NO |
5 |
Incorrect |
0 ms |
212 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 |
0 ms |
212 KB |
answer = YES |
2 |
Correct |
1 ms |
212 KB |
answer = YES |
3 |
Correct |
0 ms |
212 KB |
answer = YES |
4 |
Correct |
0 ms |
212 KB |
answer = NO |
5 |
Incorrect |
0 ms |
212 KB |
Sum of endpoints for edge (5; 3) differs from the expected value 2. |
6 |
Halted |
0 ms |
0 KB |
- |