제출 #709062

#제출 시각아이디문제언어결과실행 시간메모리
709062null_aweGraph (BOI20_graph)C++14
0 / 100
1 ms340 KiB
#include <iostream> #include <vector> #include <queue> #include <climits> using namespace std; #define ll long long #define pii pair<int, int> const double EPS = 0.000001; struct line { int m, b; line() {} line(int m, int b) : m(m), b(b) {} double combine(line other) { int mm = m - other.m, bb = other.b - b; if (mm == 0 && bb) { cout << "NO\n"; exit(0); } if (mm == 0) return INT_MAX; return (double) bb / mm; } }; int n, m; vector<vector<pii>> adj; vector<line> lines; vector<bool> vis; vector<double> all; void solve(int fv) { if (vis[fv]) return; lines[fv] = line(1, 0); queue<int> q; vector<int> has; vis[fv] = true, q.push(fv), has.push_back(fv); double ans = INT_MAX; while (q.size()) { int v = q.front(); q.pop(); for (pii p : adj[v]) { int u = p.first, c = p.second; line change(-lines[v].m, c - lines[v].b); if (!vis[u]) { vis[u] = true, q.push(u), has.push_back(u); lines[u] = change; } else { if (ans > INT_MAX - 1) ans = lines[u].combine(change); } } } if (ans > INT_MAX - 1) { ll mn = LLONG_MAX; int val = 0; for (int v : has) { line l = lines[v]; int t = -l.b / l.m; ll sum = 0; for (int u : has) { line _l = lines[u]; sum += abs(_l.m * t + _l.b); } if (sum < mn) mn = sum, ans = t; } } for (int v : has) vis[v] = false; all[fv] = ans; q = queue<int>(); vis[fv] = true, q.push(fv); while (q.size()) { int v = q.front(); q.pop(); for (pii p : adj[v]) { int u = p.first, c = p.second; if (vis[u]) continue; vis[u] = true, q.push(u); all[u] = c - all[v]; } } } int main() { cin >> n >> m; adj.resize(n); for (int i = 0; i < m; ++i) { int a, b, c; cin >> a >> b >> c; --a, --b; adj[a].push_back({b, c}), adj[b].push_back({a, c}); } lines = vector<line>(n); vis = vector<bool>(n); all.resize(n); for (int i = 0; i < n; ++i) solve(i); cout << "YES\n"; for (double val : all) cout << val << ' '; cout << '\n'; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

Graph.cpp: In function 'void solve(int)':
Graph.cpp:59:9: warning: unused variable 'val' [-Wunused-variable]
   59 |     int val = 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...