Submission #1240274

#TimeUsernameProblemLanguageResultExecution timeMemory
1240274hainam2k9Putovanje (COCI20_putovanje)C++20
0 / 110
1095 ms19776 KiB
#include <bits/stdc++.h> #define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0) #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout) #define ll long long #define ull unsigned long long #define i128 __int128 #define db long double #define sz(a) ((int)(a).size()) #define pb emplace_back #define pf emplace_front #define pob pop_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define fi first #define se second #define ins emplace #define mp make_pair using namespace std; const int MOD = 1e9+7, MAXN = 2e5+5; const string NAME = ""; struct Edge{ int to,cost[2]; Edge(int a, int b, int c){ to=a, cost[0]=b, cost[1]=c; } }; int n,depth[MAXN],par[MAXN][20],diff[MAXN],diff2[MAXN]; ll rs=0; vector<Edge> adj[MAXN]; void dfs(int u){ for(Edge& e : adj[u]){ if(e.to==par[u][0]) continue; depth[e.to]=depth[u]+1, par[e.to][0]=u; for(int i = 1; i<=__lg(n); ++i) par[e.to][i]=par[par[e.to][i-1]][i-1]; dfs(e.to); } } void dfs2(int u){ for(Edge& e : adj[u]){ if(e.to==par[u][0]) continue; diff[e.to]+=diff[u]; rs+=min(1ll*diff[e.to]*e.cost[0],1ll*e.cost[1]); diff[e.to]+=diff2[e.to]; dfs2(e.to); } } inline int lift(int x, int k){ for(int i = 0; i<=__lg(k); ++i) if((k>>i)&1) x=par[x][i]; return x; } int LCA(int x, int y){ if(depth[x]!=depth[y]){ if(depth[x]<depth[y]) swap(x,y); x=lift(x,depth[x]-depth[y]); } if(x==y) return x; for(int i = __lg(n); i>=0; --i) if(par[x][i]!=par[y][i]) x=par[x][i], y=par[y][i]; return par[x][0]; } void upd(int l, int r){ if(l==r) return; --diff2[r]; r=lift(r,depth[r]-depth[l]-1); ++diff[r]; } int main() { tt; if(fopen((NAME + ".INP").c_str(), "r")) fo; cin >> n; for(int i = 1; i<n; ++i){ int a,b,c,d; cin >> a >> b >> c >> d; adj[a].pb(Edge(b,c,d)), adj[b].pb(Edge(a,c,d)); } dfs(1); for(int i = 2; i<=n; ++i){ int lca=LCA(i,i-1); upd(lca,i), upd(lca,i-1); } // dfs2(1); // cout << rs; cout << 1; }

Compilation message (stderr)

putovanje.cpp: In function 'int main()':
putovanje.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
putovanje.cpp:73:45: note: in expansion of macro 'fo'
   73 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
putovanje.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
putovanje.cpp:73:45: note: in expansion of macro 'fo'
   73 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...