Submission #557631

#TimeUsernameProblemLanguageResultExecution timeMemory
557631JomnoiGraph (BOI20_graph)C++17
100 / 100
160 ms25408 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 10; const int INF = 1e9 + 7; int cnt_component; vector <pair <int, int>> graph[MAX_N]; vector <int> node[MAX_N]; int component[MAX_N]; int A[MAX_N], B[MAX_N]; double X[MAX_N]; void dfs(int u, int p, int now_component, int a, int b) { A[u] = a, B[u] = b; component[u] = now_component; node[now_component].push_back(u); for(auto [v, c] : graph[u]) { if(v == p) { continue; } int na = -a, nb = c - b; if(component[v] != 0) { if(A[v] == na) { if(B[v] != nb) { cout << "NO"; exit(0); } } else { double x = 1.0 * (B[v] - nb) / (na - A[v]); if(X[now_component] != INF and X[now_component] != x) { cout << "NO"; exit(0); } X[now_component] = x; } } else { dfs(v, u, now_component, na, nb); } } } int main() { cin.tie(nullptr)->sync_with_stdio(false); int N, M; cin >> N >> M; while(M--) { int a, b, c; cin >> a >> b >> c; graph[a].emplace_back(b, c); graph[b].emplace_back(a, c); } fill(X + 1, X + N + 1, INF); for(int i = 1; i <= N; i++) { if(component[i] != 0) { continue; } dfs(i, -1, ++cnt_component, 1, 0); if(X[cnt_component] == INF) { vector <int> median; for(auto v : node[cnt_component]) { median.push_back(-A[v] * B[v]); } sort(median.begin(), median.end()); X[cnt_component] = median[median.size() / 2]; } } cout << "YES\n"; for(int i = 1; i <= N; i++) { cout << fixed << setprecision(9) << A[i] * X[component[i]] + B[i] << ' '; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...