# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
675543 |
2022-12-27T12:22:06 Z |
stevancv |
Graph (BOI20_graph) |
C++14 |
|
1 ms |
448 KB |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 3e5 + 2;
const int mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
u -= 1; v -= 1;
g[u].push_back({v, w});
g[v].push_back({u, w});
}
vector<int> comp, was(n);
vector<double> (ans);
vector<vector<pair<int, int>>> r(n);
function<void(int, int, int, int)> Dfs = [&] (int s, int e, int a, int b) {
cout << s << sp << a << sp << b << endl;
was[s] = 1;
r[s].push_back({a, b});
comp.push_back(s);
for (auto u : g[s]) {
if (u.first == e) continue;
if (was[u.first] == 0) {
Dfs(u.first, s, -a, u.second - b);
}
else {
int aa = r[u.first].back().first;
int bb = r[u.first].back().second;
r[s].push_back({-aa, u.second - bb});
}
}
};
for (int i = 0; i < n; i++) {
if (was[i] == 1) continue;
Dfs(i, -1, 1, 0);
int ok = 1;
double pot = 5;
for (int j : comp) {
sort(r[j].begin(), r[j].end());
r[j].erase(unique(r[j].begin(), r[j].end()), r[j].end());
for (int k = 1; k < r[j].size(); k++) {
if (r[j][k].first == r[j][k - 1].first) {
cout << "NO\n";
return 0;
}
double x = (double)(r[j][k].second - r[j][k - 1].second) / (r[j][k - 1].first - r[j][k].first);
if (pot == 5) pot = x;
else if (pot != x) {
cout << "NO\n";
return 0;
}
}
}
if (pot == 5) pot = 0;
for (int j : comp) {
ans[j] = 1.0 * r[j][0].first * pot + r[j][0].second;
cout << j << sp << ans[j] << endl;
}
}
cout << "YES\n";
for (int i = 0; i < n; i++) cout << fixed << showpoint << setprecision(2) << ans[i] << en;
return 0;
}
Compilation message
Graph.cpp: In function 'int main()':
Graph.cpp:26:20: warning: unnecessary parentheses in declaration of 'ans' [-Wparentheses]
26 | vector<double> (ans);
| ^
Graph.cpp:53:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int k = 1; k < r[j].size(); k++) {
| ~~^~~~~~~~~~~~~
Graph.cpp:48:13: warning: unused variable 'ok' [-Wunused-variable]
48 | int ok = 1;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
448 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
448 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
448 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
448 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
448 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |