제출 #945428

#제출 시각아이디문제언어결과실행 시간메모리
945428LucaIlieGraph (BOI20_graph)C++17
0 / 100
1 ms4724 KiB
#include <bits/stdc++.h> using namespace std; struct edge { int u, v, c; int other( int x ) { return u ^ v ^ x; } }; const int MAX_N = 1e5; const int MAX_M = 2e5; bool vis[MAX_N + 1]; int a[MAX_N + 1], b[MAX_N + 1]; double val[MAX_N + 1]; edge edges[MAX_M]; vector<int> adj[MAX_N + 1]; bool sePoate; bool fixedX; double x; vector<int> vert; void dfs( int u ) { vert.push_back( u ); vis[u] = true; for ( int e: adj[u] ) { int v = edges[e].other( u ), c = edges[e].c; if ( !vis[v] ) { a[v] = -a[u]; b[v] = c - b[u]; dfs( v ); } else { if ( a[u] + a[v] == 0 ) { if ( b[u] + b[v] != c ) sePoate = false; } else { double xx = ((double)c - b[u] - b[v]) / (a[u] + a[v]); if ( fixedX && x != xx ) sePoate = false; else { fixedX = true; x = xx; } } } } } int main() { int n, m; cin >> n >> m; for ( int i = 0; i < m; i++ ) { cin >> edges[i].u >> edges[i].v >> edges[i].c; adj[edges[i].u].push_back( i ); adj[edges[i].v].push_back( i ); } for ( int v = 1; v <= n; v++ ) { if ( vis[v] ) continue; a[v] = 1; b[v] = 0; sePoate = true; fixedX = false; vert.clear(); dfs( v ); if ( !sePoate ) { cout << "NO\n"; return 0; } if ( !fixedX ) x = 0; for ( int u: vert ) val[u] = x * a[u] + b[u]; } cout << "YES\n"; for ( int v = 1; v <= n; v++ ) cout << val[v] << " "; 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...