Submission #999432

# Submission time Handle Problem Language Result Execution time Memory
999432 2024-06-15T13:25:20 Z amine_aroua Highway Tolls (IOI18_highway) C++17
51 / 100
220 ms 262144 KB
#include<bits/stdc++.h>
using namespace std;
#define intt long long
#define pb push_back
#define forr(i , x , y) for(int i = x; i <= y;i++)
#define fore(i , n) for(int i = 0 ; i < n;i++)
#define forn(i ,x , y) for(int i = x ; i >= y;i--)
long long ask(const vector<int> &w);
void answer(int s, int t);
const int MAXN = 90001;
intt a , b;
vector<pair<int ,int>> adj[MAXN];
vector<int> zeros , ones;
vector<int> nodes;
vector<pair<int ,int>> nds;
intt val;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void dfs(int x , int p  , intt dep)
{
    if(dep == (val/b))
    {
        nodes.pb(x);
        return;
    }
    for(auto [u , i] : adj[x])
    {
        if(u == p)
            continue;
        dfs(u , x ,dep + 1 );
    }
}
void dfs1(int x , int p , int dep)
{
    nds.pb({dep , x});
    for(auto u : adj[x])
    {
        if(u.first == p)
            continue;
        dfs1(u.first , x , dep + 1);
    }
}
int findT(int S)
{
    dfs(S , -1  , 0);
    int l = 0 , r = (int)nodes.size();
    vector<int> asked = ones;
    while(l + 1 < r)
    {
        int mid = (l + r)/2;
        asked = ones;
        forr(j , 0 , mid - 1) {
            for(auto [u , i] : adj[nodes[j]])
                asked[i] = 0;
        }
        if(ask(asked) == val)
            l = mid;
        else
            r = mid;
    }
    return nodes[l];
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B)
{

    a = A , b = B;
    int m = (int)U.size();
    zeros.assign(m , 0);
    ones.assign(m , 1);
    fore(i , N)adj[i].clear();
    val = ask(ones);
    fore(i , m)
    {
        adj[U[i]].pb({V[i] , i});
        adj[V[i]].pb({U[i] , i});
    }
    dfs1(0 , -1 , 0);
    sort(nds.rbegin() , nds.rend());
    int l = 0 , r = (int)nds.size();
    vector<int> asked = ones;
    while(l + 1 < r)
    {
        int mid = (l + r)/2;
        asked = ones;
        forr(j , 0 , mid - 1) {
            for(auto i : adj[nds[j].second])asked[i.second] = 0;
        }
        if(ask(asked) == val)
            l = mid;
        else
            r = mid;
    }
    int S = nds[l].second;
    answer(S , findT(S));
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 2 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 2 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 10 ms 3160 KB Output is correct
3 Correct 99 ms 9544 KB Output is correct
4 Correct 93 ms 9508 KB Output is correct
5 Correct 92 ms 9776 KB Output is correct
6 Correct 87 ms 9484 KB Output is correct
7 Correct 99 ms 9552 KB Output is correct
8 Correct 91 ms 9452 KB Output is correct
9 Correct 100 ms 9524 KB Output is correct
10 Correct 92 ms 9500 KB Output is correct
11 Correct 85 ms 10268 KB Output is correct
12 Correct 95 ms 10828 KB Output is correct
13 Correct 83 ms 10284 KB Output is correct
14 Correct 95 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3924 KB Output is correct
2 Correct 17 ms 5128 KB Output is correct
3 Correct 21 ms 6352 KB Output is correct
4 Correct 63 ms 14308 KB Output is correct
5 Correct 60 ms 14436 KB Output is correct
6 Correct 66 ms 14332 KB Output is correct
7 Correct 69 ms 14320 KB Output is correct
8 Correct 73 ms 14496 KB Output is correct
9 Correct 65 ms 14520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 9 ms 3304 KB Output is correct
3 Correct 65 ms 7852 KB Output is correct
4 Correct 87 ms 9416 KB Output is correct
5 Correct 78 ms 9368 KB Output is correct
6 Correct 85 ms 9444 KB Output is correct
7 Correct 85 ms 9396 KB Output is correct
8 Correct 100 ms 9440 KB Output is correct
9 Correct 90 ms 9684 KB Output is correct
10 Correct 98 ms 9556 KB Output is correct
11 Correct 87 ms 9672 KB Output is correct
12 Correct 81 ms 10748 KB Output is correct
13 Correct 86 ms 10380 KB Output is correct
14 Correct 76 ms 10740 KB Output is correct
15 Correct 89 ms 9412 KB Output is correct
16 Correct 77 ms 9232 KB Output is correct
17 Correct 78 ms 10572 KB Output is correct
18 Correct 89 ms 10096 KB Output is correct
19 Correct 94 ms 9452 KB Output is correct
20 Correct 72 ms 11196 KB Output is correct
21 Correct 81 ms 10116 KB Output is correct
22 Correct 79 ms 10112 KB Output is correct
23 Correct 92 ms 10088 KB Output is correct
24 Correct 101 ms 10576 KB Output is correct
25 Correct 88 ms 14060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 196 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 220 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -