이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
int n, m;
long long a, b, ret;
bool use[130005], fi = true;
vector<int> st, u, v, ed[100005];
set<int> pos;
int dfs(int nw, int fa, long long sum, long long tar)
{
    if (fi && sum == tar)
    {
        pos.insert(nw);
        return 1;
    }
    if (sum == tar && pos.find(nw) != pos.end())
        return 1;
    if (pos.find(nw) != pos.end())
        pos.erase(nw);
    int g[2] = {0, 0};
    vector<pair<int, int>> c;
    for (auto _ : ed[nw])
    {
        int go = u[_] ^ v[_] ^ nw;
        if (go == fa || !use[_])
            continue;
        ret = dfs(go, nw, sum + ((st[_] == 0) ? a : b), tar);
        if (ret)
            c.pb({ret, _});
        else
            use[_] = false;
    }
    sort(all(c));
    for (int i = sz(c) - 1; i >= 0; i--)
    {
        if (g[0] > g[1])
        {
            g[1] += c[i].f;
            st[c[i].s] = 1;
        }
        else
        {
            g[0] += c[i].f;
            st[c[i].s] = 0;
        }
    }
    return g[0] + g[1];
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B)
{
    m = sz(U);
    n = N, u = U, v = V, a = A, b = B;
    for (int i = 0; i < m; i++)
    {
        ed[u[i]].pb(i);
        ed[v[i]].pb(i);
        use[i] = true;
    }
    st = vector<int>(m, 0);
    while (1)
    {
        ret = ask(st);
        ret = dfs(0, 0, 0ll, ret);
        if (ret == 1ll)
        {
            answer(0, *pos.begin());
            return;
        }
        fi = false;
    }
    answer(0, n - 1);
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |