Submission #883817

#TimeUsernameProblemLanguageResultExecution timeMemory
883817vjudge1Putovanje (COCI20_putovanje)C++17
0 / 110
1029 ms39496 KiB
#include <bits/stdc++.h> using namespace std; #define sp << " " << #define int long long #define vi vector<int> #define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++) #define pii pair<int,int> const int N = 2e5+1; int t = 1; vi edges[N],v(N),w(N),pass(N,0); set<int> sts[N]; map<pii,int> edg; int n; void dfs(int node,int p) { for (auto it : edges[node]) if (it != p) dfs(it,node); for (auto it : edges[node]) { if (it == p) continue; for (auto itt : sts[it]) { int c = (itt>1)+(itt<n); c-=(itt>1 && sts[it].count(itt-1)); c-=(itt<n && sts[it].count(itt+1)); pass[edg[{node,it}]]+=c; } } sts[node].insert(node); for (auto it : edges[node]) { if (it == p) continue; if (sts[it].size() > sts[node].size()) sts[node].swap(sts[it]); for (auto itt : sts[it]) sts[node].insert(it); } return; } void solve() { cin >> n; F(i,n-1) { int a,b; cin >> a >> b >> v[i] >> w[i]; edges[a].push_back(b); edges[b].push_back(a); edg[{a,b}] = edg[{b,a}] = i; } dfs(1,1); int ans = 0; F(i,n-1) { if (pass[i]*v[i] <= w[i]) ans+=pass[i]*v[i]; else ans+=w[i]; } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef Local freopen("in","r",stdin); freopen("out","w",stdout); #endif int t = 1; //cin >> t; F(i,t) solve(); }

Compilation message (stderr)

putovanje.cpp: In function 'void dfs(long long int, long long int)':
putovanje.cpp:29:15: warning: unused variable 'itt' [-Wunused-variable]
   29 |     for (auto itt : sts[it]) sts[node].insert(it);
      |               ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...