답안 #587613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587613 2022-07-02T06:49:15 Z Bobonbush 경주 (Race) (IOI11_race) C++17
100 / 100
1162 ms 40176 KB
#include <bits/stdc++.h>
#define foreach for
#define in :
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;

/*
Konichiwa
Konichiwa
Ara ~~ ara

Bob no taisuki - Shinobu Kocho
    * * * * *
  *          *
 *         *
*         *        I love SHINOBU <3 <3 <3
 *         *
  *          *
    * * * * *
*/

/*
_________________________


    Author : Bob15324

_________________________
*/

template<class X , class Y>
    bool Minimize(X & x , Y y)
    {
        if( x == -1 || x >y )
        {
            x = y;
            return true;
        }
        return false;
    }

template<class X , class Y>
    bool Maximize(X & x , Y y)
    {
        if( x < y)
        {
            x = y;
            return true;
        }
        return false;
    }

/* End of templates. Let's see what do we have here */
const int N = 2e5+1;
vector<pair<int ,int >>vertices[N];
int sub_size[N];
int k ;
bool dead[N];
int res = -1;

    void AddEdge(int u ,int v ,int w)
        {
            vertices[u].push_back(make_pair(v , w));
            vertices[v].push_back(make_pair(u , w));
        }

        int DFS(int u ,int daddy)
        {
            sub_size[u] = 1;
            foreach(pair<int ,int > adj in vertices[u])
            {
                int v = adj.first;
                if(v == daddy || dead[v])
                {
                    continue;
                }
                sub_size[u] += DFS(v , u);
            }
            return  sub_size[u];
        }

        int centroid(int u ,int daddy , int lim)
        {
            foreach(pair<int ,int > adj in vertices[u])
            {
                int v = adj.first;
                if(v == daddy || dead[v])
                {
                    continue;
                }
                if(sub_size[v] > lim)
                {
                    return centroid(v , u , lim);
                }
            }
            return u;
        }

        void dfs2(int u ,int daddy  , int distance , map<int ,int > &cur , int s )
        {
            if(cur.count(s))
            {
                Minimize(cur[s] , distance);
                
            }else
            {
                //cout << distance <<'\n';
                cur[s] = distance;
            }
            foreach(pair<int ,int > adj in vertices[u])
            {
                int v = adj.first;
                if(v == daddy || dead[v])
                {
                    continue;
                }
                if(s + adj.second > k)
                {
                    continue;
                }
                dfs2(v , u , distance + 1 ,cur ,  s + adj.second );
            }
        }

        void Build(int u, int daddy  )
        {
            int lim = DFS(u , daddy);
            int _c = centroid(u , daddy , lim >> 1);

            dead[_c] = true;

            map<int ,int >dict;
            foreach(pair<int ,int > adj in vertices[_c])
            {
                
                int v = adj.first;
                if(dead[v])
                {
                    continue;
                }
                
                map<int ,int >cur;
                dfs2(v , _c , 1 ,cur ,  adj.second  );
                foreach(auto val in cur)
                {
                    if(dict.count(k - val.first))
                    {
                        
                        Minimize(res  , dict[k - val.first] + val.second);
                        
                    }
                }

                foreach(auto val in cur)
                {
                    if(dict.count(val.first))
                    {
                        Minimize(dict[val.first] , val.second);
                    }else
                    {
                        dict[val.first] = val.second;
                    }
                }
            }
            if(dict.count(k))
            {
                foreach(auto val in dict)
                {
                    if(val.first == k)
                        Minimize(res , val.second);
                }
            }
            dict.clear();

            foreach(pair<int ,int >adj in vertices[_c])
            {
                int v = adj.first;
                if(dead[v])
                {
                    continue;
                }
                Build(v , _c  );
            }
        }



int best_path(int n , int m ,int H[N][2] , int L[N])
{
    k = m;
    for(int i = 0 ; i < n -1 ; i++)
    {
        AddEdge(H[i][0] + 1 , H[i][1] + 1 , L[i]);
    }
    Build(1 , - 1 );
    return res;
}

//Ehem. My code is amazing. Pay me 2$.Thank you.
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5000 KB Output is correct
4 Correct 3 ms 5000 KB Output is correct
5 Correct 2 ms 5004 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4984 KB Output is correct
9 Correct 3 ms 5000 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5004 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5000 KB Output is correct
4 Correct 3 ms 5000 KB Output is correct
5 Correct 2 ms 5004 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4984 KB Output is correct
9 Correct 3 ms 5000 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5004 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5004 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 5076 KB Output is correct
22 Correct 4 ms 5004 KB Output is correct
23 Correct 4 ms 5012 KB Output is correct
24 Correct 5 ms 5016 KB Output is correct
25 Correct 6 ms 5140 KB Output is correct
26 Correct 5 ms 5076 KB Output is correct
27 Correct 4 ms 5016 KB Output is correct
28 Correct 4 ms 5020 KB Output is correct
29 Correct 5 ms 5016 KB Output is correct
30 Correct 5 ms 5076 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 4 ms 5076 KB Output is correct
33 Correct 5 ms 5076 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5008 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 4 ms 5096 KB Output is correct
38 Correct 5 ms 5012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5000 KB Output is correct
4 Correct 3 ms 5000 KB Output is correct
5 Correct 2 ms 5004 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4984 KB Output is correct
9 Correct 3 ms 5000 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5004 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5004 KB Output is correct
19 Correct 250 ms 11684 KB Output is correct
20 Correct 191 ms 11684 KB Output is correct
21 Correct 199 ms 11700 KB Output is correct
22 Correct 221 ms 11832 KB Output is correct
23 Correct 82 ms 12012 KB Output is correct
24 Correct 82 ms 11904 KB Output is correct
25 Correct 115 ms 12768 KB Output is correct
26 Correct 106 ms 15792 KB Output is correct
27 Correct 221 ms 18800 KB Output is correct
28 Correct 252 ms 24012 KB Output is correct
29 Correct 295 ms 23412 KB Output is correct
30 Correct 208 ms 18752 KB Output is correct
31 Correct 210 ms 18636 KB Output is correct
32 Correct 259 ms 18844 KB Output is correct
33 Correct 326 ms 17540 KB Output is correct
34 Correct 196 ms 18436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 5000 KB Output is correct
4 Correct 3 ms 5000 KB Output is correct
5 Correct 2 ms 5004 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4984 KB Output is correct
9 Correct 3 ms 5000 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5004 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5004 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 5076 KB Output is correct
22 Correct 4 ms 5004 KB Output is correct
23 Correct 4 ms 5012 KB Output is correct
24 Correct 5 ms 5016 KB Output is correct
25 Correct 6 ms 5140 KB Output is correct
26 Correct 5 ms 5076 KB Output is correct
27 Correct 4 ms 5016 KB Output is correct
28 Correct 4 ms 5020 KB Output is correct
29 Correct 5 ms 5016 KB Output is correct
30 Correct 5 ms 5076 KB Output is correct
31 Correct 4 ms 5076 KB Output is correct
32 Correct 4 ms 5076 KB Output is correct
33 Correct 5 ms 5076 KB Output is correct
34 Correct 4 ms 5076 KB Output is correct
35 Correct 4 ms 5008 KB Output is correct
36 Correct 4 ms 5076 KB Output is correct
37 Correct 4 ms 5096 KB Output is correct
38 Correct 5 ms 5012 KB Output is correct
39 Correct 250 ms 11684 KB Output is correct
40 Correct 191 ms 11684 KB Output is correct
41 Correct 199 ms 11700 KB Output is correct
42 Correct 221 ms 11832 KB Output is correct
43 Correct 82 ms 12012 KB Output is correct
44 Correct 82 ms 11904 KB Output is correct
45 Correct 115 ms 12768 KB Output is correct
46 Correct 106 ms 15792 KB Output is correct
47 Correct 221 ms 18800 KB Output is correct
48 Correct 252 ms 24012 KB Output is correct
49 Correct 295 ms 23412 KB Output is correct
50 Correct 208 ms 18752 KB Output is correct
51 Correct 210 ms 18636 KB Output is correct
52 Correct 259 ms 18844 KB Output is correct
53 Correct 326 ms 17540 KB Output is correct
54 Correct 196 ms 18436 KB Output is correct
55 Correct 27 ms 5992 KB Output is correct
56 Correct 17 ms 5588 KB Output is correct
57 Correct 129 ms 11828 KB Output is correct
58 Correct 55 ms 11556 KB Output is correct
59 Correct 413 ms 21580 KB Output is correct
60 Correct 1154 ms 40176 KB Output is correct
61 Correct 307 ms 19120 KB Output is correct
62 Correct 360 ms 19088 KB Output is correct
63 Correct 394 ms 19056 KB Output is correct
64 Correct 1162 ms 25692 KB Output is correct
65 Correct 252 ms 19668 KB Output is correct
66 Correct 756 ms 22868 KB Output is correct
67 Correct 141 ms 19528 KB Output is correct
68 Correct 474 ms 23236 KB Output is correct
69 Correct 443 ms 23268 KB Output is correct
70 Correct 463 ms 22500 KB Output is correct