Submission #888707

#TimeUsernameProblemLanguageResultExecution timeMemory
888707vjudge1Two Currencies (JOI23_currencies)C++17
0 / 100
3 ms19292 KiB
#include <bits/stdc++.h> using namespace std;/* <<<<It's never too late for a new beginning in your life>>>> Today is hard tomorrow will worse but the day after tomorrow will be the sunshine.. HARD WORK BEATS TALENT WHEN TALENT DOESN'T WORK HARD............ Never give up */ //The most CHALISHKANCHIK #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() #define int long long typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vii; const int N = 100005; vi g[N]; //~ pii p[N]; map<pii, vi> mp; int t; int pre[N]; int n, q, timer; int tin[N], tout[N]; int up[20][N]; int num[N]; void dfs(int v, int pr, int cnt){ num[v] = cnt; tin[v] = ++timer; up[0][v] = pr; for (int i = 1; i <= 19; i++) { up[i][v] = up[i - 1][ up[i - 1][v] ]; } for (int to : g[v]) { if (to == pr) continue; //~ pre[to] = v; dfs(to, v, cnt+mp[{v, to}].size()); } tout[v] = timer; } bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; } int lca(int a, int b) { if (upper(a, b)) return a; if (upper(b, a)) return b; for (int i = 19; i >= 0; i--) { if (!upper(up[i][a], b)) { a = up[i][a]; } } return up[0][a]; } void solve(){ int n, m, q; cin >> n >> m >> q; vii cui; int cc =0 ; for(int i = 0; i < n-1; i++){ int a, b; cin >> a >> b; g[a].pb(b); g[b].pb(a); cui.pb({a, b}); } for(int i = 0; i < m; i++){ int j, c; cin >> j >> c;j--; mp[cui[j]].pb(c); mp[{cui[j].ss, cui[j].ff}].pb(c); cc = c; } dfs(1, -1, 0); while(q--){ int a, b, x, y; cin >> a >> b >> x >> y; int cnt = num[a] + num[b] - (2 * num[lca(a, b)]); cnt -= (y/cc); y -= (y/cc)*cc; x -= cnt; cout << (x < 0 ? -1 : x) << '\n'; } } main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int t = 1; //~ cin >> t; while(t--){ solve(); } }

Compilation message (stderr)

currencies.cpp:89:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   89 | 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...