Submission #598084

# Submission time Handle Problem Language Result Execution time Memory
598084 2022-07-17T14:25:17 Z mayureshpatle Race (IOI11_race) C++17
100 / 100
476 ms 106232 KB
/**************************************************************
Submitted By: Mayuresh N. Patle
Written On: Saturday, July 16, 2022
**************************************************************/
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod1 998244353
#define rep(i,s,e) for(i=s;i<e;++i)
#define repr(i,s,e) for(i=s;i>e;--i)
#define fp(i) fixed<<setprecision(i)
#define in(a) for(auto &ghe:a) cin>>ghe;
#define in2d(a) for(auto &ghe:a) for(auto &he:ghe) cin>>he;
#define out(a) for(auto &ghe:a) cout<<ghe<<" ";cout<<endl;
#define out2d(a) {for(auto &he:a) {out(he)}}
#define loop(i,a) for(auto &i:a)
#define inrange(i,j,k) (((i)<=(j)) && ((j)<(k)))
#define make(a,i) memset(a,i,sizeof(a))
#define chk(x) cerr<<(#x)<<":"<<(x)<<endl;
#define chk2(x,y) cerr<<(#x)<<":"<<(x)<<" "<<(#y)<<":"<<(y)<<endl;
#define chk3(x,y,z) cerr<<(#x)<<":"<<(x)<<" "<<(#y)<<":"<<(y)<<" "<<(#z)<<":"<<(z)<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <ll> vll;
typedef vector <float> vf;
typedef vector <ld> vld;
#define pb push_back
#define pob() pop_back()
typedef pair <ll,ll> pll;
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
typedef vector <pll> vp;
typedef vector <bool> flags;
#define all(v) begin(v),end(v)
#define amin(var, val) var = (val)<var ? (val) : var
#define amax(var, val) var = (val)>var ? (val) : var
#define xiny(x,y) (y.find(x)!=y.end())

const ll maxN = 2e5+1;

class edge{
    public:
    ll u,v,w;
    edge(){}
    edge(ll u, ll v, ll w): u(u), v(v), w(w){}
    ll op(ll x) {return u^v^x;}
};

vll G[maxN];
vector <edge> e;
map <ll, ll> m[maxN];
ll k;

pll dfs(ll v, ll p, int& ans)
{
    ll da=0, la=0;
    m[v][0] = 0;
    loop(i, G[v])
    {
        if(ans==1) return {0,0};
        ll u=e[i].op(v), w=e[i].w;
        if(u==p) continue;

        if(w==k)
        {
            ans=1;
            return {0,0};
        }

        pll res = dfs(u, v, ans);

        ll cda = w + res.F;
        ll cla = 1 + res.S;

        if(m[u].size()>m[v].size())
        {
            swap(m[u], m[v]);
            swap(da, cda);
            swap(la, cla);
        }

        loop(p, m[u])
        {
            ll rd = p.F + cda;
            ll rl = p.S + cla;
            if(rd == k) amin(ans, rl);
            else if(rd < k)
            {
                ll reqd = k - rd - da;
                if(xiny(reqd, m[v])) amin(ans, rl + m[v][reqd] + la);
            }
        }

        loop(p, m[u])
        {
            ll rd = p.F + cda;
            ll rl = p.S + cla;
            if(rd < k)
            {
                rd -= da;
                rl -= la;
                if(xiny(rd, m[v])) amin(m[v][rd], rl);
                else m[v][rd] = rl;
            }
        }
    }
    return {da, la};
}


int best_path(int n, int K, int H[][2], int L[])
{
    k=K;
    ll i;
    rep(i,0,n-1)
    {
        ll u=H[i][0], v=H[i][1], w=L[i];
        G[u].pb(e.size());
        G[v].pb(e.size());
        e.pb(edge(u,v,w));
    }
    int ans = maxN;
    dfs(0, -1, ans);
    if(ans==maxN) ans=-1;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14408 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14420 KB Output is correct
5 Correct 8 ms 14388 KB Output is correct
6 Correct 8 ms 14368 KB Output is correct
7 Correct 9 ms 14396 KB Output is correct
8 Correct 9 ms 14420 KB Output is correct
9 Correct 8 ms 14404 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 8 ms 14404 KB Output is correct
14 Correct 8 ms 14348 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 9 ms 14420 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 8 ms 14420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14408 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14420 KB Output is correct
5 Correct 8 ms 14388 KB Output is correct
6 Correct 8 ms 14368 KB Output is correct
7 Correct 9 ms 14396 KB Output is correct
8 Correct 9 ms 14420 KB Output is correct
9 Correct 8 ms 14404 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 8 ms 14404 KB Output is correct
14 Correct 8 ms 14348 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 9 ms 14420 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 8 ms 14420 KB Output is correct
19 Correct 8 ms 14292 KB Output is correct
20 Correct 10 ms 14344 KB Output is correct
21 Correct 9 ms 14676 KB Output is correct
22 Correct 8 ms 14548 KB Output is correct
23 Correct 9 ms 14548 KB Output is correct
24 Correct 9 ms 14548 KB Output is correct
25 Correct 11 ms 14652 KB Output is correct
26 Correct 9 ms 14548 KB Output is correct
27 Correct 8 ms 14548 KB Output is correct
28 Correct 9 ms 14676 KB Output is correct
29 Correct 9 ms 14676 KB Output is correct
30 Correct 10 ms 14676 KB Output is correct
31 Correct 9 ms 14676 KB Output is correct
32 Correct 9 ms 14732 KB Output is correct
33 Correct 8 ms 14760 KB Output is correct
34 Correct 8 ms 14668 KB Output is correct
35 Correct 8 ms 14548 KB Output is correct
36 Correct 8 ms 14660 KB Output is correct
37 Correct 8 ms 14548 KB Output is correct
38 Correct 8 ms 14676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14408 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14420 KB Output is correct
5 Correct 8 ms 14388 KB Output is correct
6 Correct 8 ms 14368 KB Output is correct
7 Correct 9 ms 14396 KB Output is correct
8 Correct 9 ms 14420 KB Output is correct
9 Correct 8 ms 14404 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 8 ms 14404 KB Output is correct
14 Correct 8 ms 14348 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 9 ms 14420 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 8 ms 14420 KB Output is correct
19 Correct 138 ms 38512 KB Output is correct
20 Correct 150 ms 38484 KB Output is correct
21 Correct 137 ms 38272 KB Output is correct
22 Correct 145 ms 37800 KB Output is correct
23 Correct 61 ms 23316 KB Output is correct
24 Correct 110 ms 37796 KB Output is correct
25 Correct 101 ms 39160 KB Output is correct
26 Correct 63 ms 47388 KB Output is correct
27 Correct 221 ms 50780 KB Output is correct
28 Correct 279 ms 93172 KB Output is correct
29 Correct 283 ms 90484 KB Output is correct
30 Correct 211 ms 50796 KB Output is correct
31 Correct 197 ms 50816 KB Output is correct
32 Correct 276 ms 51048 KB Output is correct
33 Correct 223 ms 56016 KB Output is correct
34 Correct 170 ms 44440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14408 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 8 ms 14420 KB Output is correct
4 Correct 8 ms 14420 KB Output is correct
5 Correct 8 ms 14388 KB Output is correct
6 Correct 8 ms 14368 KB Output is correct
7 Correct 9 ms 14396 KB Output is correct
8 Correct 9 ms 14420 KB Output is correct
9 Correct 8 ms 14404 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 8 ms 14404 KB Output is correct
14 Correct 8 ms 14348 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 9 ms 14420 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 8 ms 14420 KB Output is correct
19 Correct 8 ms 14292 KB Output is correct
20 Correct 10 ms 14344 KB Output is correct
21 Correct 9 ms 14676 KB Output is correct
22 Correct 8 ms 14548 KB Output is correct
23 Correct 9 ms 14548 KB Output is correct
24 Correct 9 ms 14548 KB Output is correct
25 Correct 11 ms 14652 KB Output is correct
26 Correct 9 ms 14548 KB Output is correct
27 Correct 8 ms 14548 KB Output is correct
28 Correct 9 ms 14676 KB Output is correct
29 Correct 9 ms 14676 KB Output is correct
30 Correct 10 ms 14676 KB Output is correct
31 Correct 9 ms 14676 KB Output is correct
32 Correct 9 ms 14732 KB Output is correct
33 Correct 8 ms 14760 KB Output is correct
34 Correct 8 ms 14668 KB Output is correct
35 Correct 8 ms 14548 KB Output is correct
36 Correct 8 ms 14660 KB Output is correct
37 Correct 8 ms 14548 KB Output is correct
38 Correct 8 ms 14676 KB Output is correct
39 Correct 138 ms 38512 KB Output is correct
40 Correct 150 ms 38484 KB Output is correct
41 Correct 137 ms 38272 KB Output is correct
42 Correct 145 ms 37800 KB Output is correct
43 Correct 61 ms 23316 KB Output is correct
44 Correct 110 ms 37796 KB Output is correct
45 Correct 101 ms 39160 KB Output is correct
46 Correct 63 ms 47388 KB Output is correct
47 Correct 221 ms 50780 KB Output is correct
48 Correct 279 ms 93172 KB Output is correct
49 Correct 283 ms 90484 KB Output is correct
50 Correct 211 ms 50796 KB Output is correct
51 Correct 197 ms 50816 KB Output is correct
52 Correct 276 ms 51048 KB Output is correct
53 Correct 223 ms 56016 KB Output is correct
54 Correct 170 ms 44440 KB Output is correct
55 Correct 22 ms 17672 KB Output is correct
56 Correct 16 ms 16388 KB Output is correct
57 Correct 84 ms 35872 KB Output is correct
58 Correct 56 ms 29132 KB Output is correct
59 Correct 92 ms 53688 KB Output is correct
60 Correct 284 ms 91904 KB Output is correct
61 Correct 232 ms 52888 KB Output is correct
62 Correct 217 ms 51020 KB Output is correct
63 Correct 302 ms 51144 KB Output is correct
64 Correct 476 ms 106232 KB Output is correct
65 Correct 242 ms 45280 KB Output is correct
66 Correct 288 ms 84432 KB Output is correct
67 Correct 196 ms 45428 KB Output is correct
68 Correct 409 ms 66344 KB Output is correct
69 Correct 403 ms 70616 KB Output is correct
70 Correct 358 ms 64440 KB Output is correct