Submission #859400

#TimeUsernameProblemLanguageResultExecution timeMemory
859400iskhakkutbilimGraph (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+= 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 * 1.0}); g[b].push_back({a, (long double)c * 1.0}); } vector<long double> how(n + 1); for(int i = 1;i <= n; i++){ for(int j = 1;j <= n; j++) used[j] = 0; sum = 0; cost[i] = 0; 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]; } } for(int i = 1;i <= n; i++){ for(int j = 1;j <= n; j++) used[j] = 0; sum = 0; cost[i] = 0.5; 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]; } } // cout << ans << '\n'; if(ans >= 1e18){ cout << "NO"; return 0; } cout << "YES" << '\n'; for(int i = 1;i <= n; i++) cout << how[i] << ' '; 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...