제출 #849527

#제출 시각아이디문제언어결과실행 시간메모리
849527not_from_hereRace (IOI11_race)C++14
0 / 100
1 ms2396 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#ifdef LOCAL
#include "debug.h"
#define dbg(...) debug_out(splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define dbg(...)
#endif

//#define int long long
#define itn int
#define ALL(v) (v).begin(), (v).end()
#define mem(a, x) memset(a , x , sizeof(a))
#define f first
#define s second
#define mb make_pair
#define pb push_back
#define popCnt __builtin_popcountll

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef pair <int, int> pii;
typedef vector<pair <int, int>> vpii;
typedef vector<vector<char>> vvc;

const int mod = 1e9 + 7;
const int oo = 0x5f5f5f5f;
const long double PI = acos(-1.0L);

int ceiledLog2 (int x){return __lg(x) + (__builtin_popcount(x) != 1);}
ll toLL (int first, int second, int mx){return (1LL*first*mx) + second;}

template <class T, class U> T GCD (T a, U b) {return (!b ? a : GCD(b, a%b));}
template <class T, class U> T LCM (T a, U b) {return ((a/GCD(a, b)) * b);}
template <class T> bool isSquare (T n) {T sq = sqrt(n);  return (sq*sq)==n;}
template <typename T> T Unique(T x){sort(ALL(x));x.resize(distance(x.begin(),unique(ALL(x))));return x;}
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//bool sortBySecond (pii &a, pii &b) {return a.second < b.second;} //asc

int ys[] = {-1, -1, 0, 1, 1, 1, 0, -1};     //edges [0, 2, 4, 6]
int xs[] = {0, 1, 1, 1, 0, -1, -1, -1};

//-----------------------------------------------------------------------------//

//const int N = ?e5 + 5;
ll n,k;
vector<vector<pair<ll,ll>>> g;

ll ans=2e17;
struct B_CH_SACK {
        ll n, timer = 0;
        vector<ll> lev,sz, b_ch;
        vector<ll>to;
        vector<ll> order, tin, tout;
        map<ll, ll> f;

        B_CH_SACK(ll _n = 0) {
                n = _n;
                if (n) {
                        sz.resize(n, 1);
                        to.resize(n);
                        lev.resize(n);
                        b_ch.resize(n, -1);
                        tin.resize(n);
                        tout.resize(n);
                        dfs(0, -1);
                        solve(0, -1, false);
                }
        }

        void dfs(ll u, ll p, ll t=0, ll d=0) {
                tin[u] = timer++;
                order.push_back(u);
                to[u]=t;
                lev[u]=d;
                ll mx = 0, idx = -1;
                for (auto &[v,c] : g[u]) {
                        if (v == p) continue;
                        dfs(v, u, t+c,d+1);
                        sz[u] += sz[v];
                        if (sz[v] > mx) {
                                mx = sz[v];
                                idx = v;
                        }
                }
                b_ch[u] = idx;
                tout[u] = timer-1;
        }


        void solve(ll u, ll p, bool keep) {
                for (auto &[v,c] : g[u]) {
                        if (v == p || v == b_ch[u]) continue;
                        solve(v, u, false);
                }
                if (b_ch[u] != -1) {
                        solve(b_ch[u], u, true);
                }
                if (f.count(to[u]))
                        f[to[u]]=min(f[to[u]],lev[u]);
                else
                        f[to[u]]=lev[u];
                for (auto &[v,c] : g[u]) {
                        if (v == p || v == b_ch[u]) continue;
                        for (ll i = tin[v]; i <= tout[v]; i++) {
                                ll x = order[i];
                                
                                ll d=to[x]-to[u];
                                if (d<=k) {
                                        ll dif=k-d;
                                        dif+=to[u];
                                        if (f.count(dif)){
                                                ans=min(ans, f[dif]-lev[u] + lev[x]-lev[u]);
                                        }
                                }

                                if (f.count(to[x]))
                                        f[to[x]]=min(f[to[x]],lev[x]);
                                else
                                        f[to[x]]=lev[x];
                        }
                }




                if (!keep) {
                        f.clear();
//                        for (int i = tin[u]; i <= tout[u]; i++) {
//                                int x = order[i];
//                                freq[a[x]]--;
//                        }
                }
        }
} sack;

int best_path(int N, int K, int h[][2], int l[]){
        n=N;
        k=K;
        g=vector<vector<pair<ll,ll>>>(n);
        for (int i = 0; i < n-1; ++i) {
                g[h[i][0]].pb({h[i][1], l[i]});
                g[h[i][1]].pb({h[i][0], l[i]});
        }
        sack=B_CH_SACK(n);
        if (ans > 1e17)
                return -1;
        return (int)ans;
}

컴파일 시 표준 에러 (stderr) 메시지

race.cpp: In member function 'void B_CH_SACK::dfs(ll, ll, ll, ll)':
race.cpp:87:28: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   87 |                 for (auto &[v,c] : g[u]) {
      |                            ^
race.cpp: In member function 'void B_CH_SACK::solve(ll, ll, bool)':
race.cpp:102:28: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  102 |                 for (auto &[v,c] : g[u]) {
      |                            ^
race.cpp:113:28: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  113 |                 for (auto &[v,c] : g[u]) {
      |                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...