Submission #859414

#TimeUsernameProblemLanguageResultExecution timeMemory
859414iskhakkutbilimGraph (BOI20_graph)C++17
0 / 100
2 ms7516 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define all(a) a.begin(), a.end() const int N = 2e5; int n, m; vector< pair<int, long double> > g[N+10]; int used[N+10]; long double cost[N+10]; long double sum; void dfs(int v){ used[v] = 1; sum+= abs(cost[v]); for(auto [to, c] : g[v]){ if(used[to] == 0){ cost[to] = c - cost[v]; dfs(to); }else{ } } } main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long double ans = 1e18; cin >> n >> m; for(int i = 0;i < m; i++){ int a, b, c; cin >> a >> b >> c; g[a].push_back({b, (long double)c * 10.0}); g[b].push_back({a, (long double)c * 10.0}); } vector<long double> how(n + 1); for(int start = -100; start <= 100; start++){ for(int i = 1;i <= n; i++){ for(int j = 1;j <= n; j++) used[j] = 0; sum = 0; cost[i] = start; dfs(i); int ok = 1; for(int v = 1; v <= n && ok; v++){ for(auto [to, c] : g[v]){ if(cost[v] + cost[to] != c){ ok = 0; break; } } } if(ans > sum && ok){ ans = sum; for(int j = 1;j <= n; j++) how[j] = cost[j]; } } } if(ans >= 1e18){ cout << "NO"; return 0; } cout << "YES" << '\n'; cout << fixed << setprecision(6); for(int i = 1;i <= n; i++) cout << how[i] / 10 << ' '; return 0; }

Compilation message (stderr)

Graph.cpp:28:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   28 | main(){
      | ^~~~
#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...