Submission #1299347

#TimeUsernameProblemLanguageResultExecution timeMemory
1299347floGraph (BOI20_graph)C++20
34 / 100
5 ms1856 KiB
#include <bits/stdc++.h> #define task "testing" #define ll long long #define multitest 0 using namespace std; struct Line { int a, b; }; struct Edge { int u, v, w; bool vis; }; const int N = 1e5, S = 1e8; Line a[N+5]; Edge e[2*N+5]; bool ex[N+5], check; vector<int> adj[N+5], val[N+5]; int id[N+5], mid[N+5], X[N+5], cur; void dfs(int v) { id[v] = cur; Line l[2]; for (int x = 1; x <= 2; x++) { l[x-1] = {-a[v].a, x*S-a[v].b}; } for (auto x : adj[v]) { if (e[x].vis) continue; e[x].vis = 1; int u = e[x].u^e[x].v^v; if (!id[u]) { a[u] = l[e[x].w-1], dfs(u); } else { if (a[v].a*a[u].a == -1) { X[cur] = (a[v].b-a[u].b)/(a[u].a-a[v].a); } else { X[cur] = (e[x].w*S-a[v].b-a[u].b)/(2*a[v].a), ex[cur] = 1; } } if (check) return; } } void flo(int ID) { int n, m; cin >> n >> m; for (int x = 1; x <= m; x++) { cin >> e[x].u >> e[x].v >> e[x].w; adj[e[x].u].push_back(x); adj[e[x].v].push_back(x); e[x].vis = 0; } for (int x = 1; x <= n; x++) { if (id[x]) continue; cur++, a[x] = {1, 0}, dfs(x); if (check) { cout << "NO\n"; return; } } for (int x = 1; x <= n; x++) { if (ex[id[x]]) { a[x].b = a[x].a*X[id[x]]+a[x].b; } else { val[id[x]].push_back(-a[x].a*a[x].b); } } for (int x = 1; x <= cur; x++) { if (val[x].empty()) continue; sort(val[x].begin(), val[x].end()); mid[x] = val[x][val[x].size()/2]; } for (int x = 1; x <= n; x++) { if (!ex[id[x]]) { a[x].b += a[x].a*mid[id[x]]; } } for (int x = 1; x <= m; x++) { int s = a[e[x].u].b/100+a[e[x].v].b/100; if (abs(s-e[x].w*S/100) > 5) { cout << "NO\n"; return; } } cout << "YES\n"; for (int x = 1; x <= n; x++) { if (a[x].b < 0) { a[x].b *= -1; cout << "-"; } cout << a[x].b/S << "." << a[x].b%S << " "; } cout << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int TCS = 1, ID = 1; if (multitest) { cin >> TCS; } while (TCS--) flo(ID++); return 0; }

Compilation message (stderr)

Graph.cpp: In function 'int main()':
Graph.cpp:138:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  138 |                 freopen(task".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Graph.cpp:139:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  139 |                 freopen(task".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...