답안 #838805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
838805 2023-08-27T18:52:08 Z ASN49K 경주 (Race) (IOI11_race) C++14
100 / 100
461 ms 79572 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cmath>
#include <stack>
#include <set>
#include <functional>
#include <bitset>
#include <map>
#include <unordered_map>
#include <queue>
#include <array>
#include <numeric>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename A> ostream& operator<<(ostream &os, vector<A>&a) { for(auto &c:a)os<<c<<' '; return os;}
template<typename A> istream& operator>>(istream  &os, vector<A>&a) { for(auto &c:a)os>>c; return os;}
template<typename A,size_t N> istream& operator>>(istream &os, array<A,N>&a) { for(auto &c:a)os>>c; return os;}
template<typename A,typename B> istream& operator>>(istream  &os, pair<A,B>&a) { os>>a.first>>a.second; return os;}
#define bug(a) cerr << "(" << #a << ": " << a << ")\n";
#define all(x) x.begin(),x.end()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PQ priority_queue
using pii= pair<int,int>;
using VI= vector<int>;
using v64= vector<int64_t>;
using i64= int64_t;
using i16= int16_t;
using u64= uint64_t;
using u32= uint32_t;
using i32= int32_t;
using u16= uint16_t;
const i32 inf=1e9;
const i64 INF=1e18;
const int mod=1e9+7;
const int sigma=26;
string yn(bool x){if(x)return "YES";return "NO";}

int best_path(int N, int K, int H[][2], int L[])
{
    const int n=N;
    vector<map<int,int>>mp(n);
    vector<vector<pii>>g(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]});
    }

    int rez= n + 1;
    auto _min=[&](int& x,const int& y)
    {
        if(x>y)
            x=y;
    };
    auto merge=[&](int x,int y,int h,int sum)
    {
        if(mp[x].size()<mp[y].size())
        {
            swap(mp[x],mp[y]);
        }
        for(auto &c:mp[y])
        {
            auto it=mp[x].find(K-(c.first-sum)+sum);
            if(it!=mp[x].end())
            {
                _min(rez,c.second+it->second-2*h);
            }
        }
        for(auto &c:mp[y])
        {
            if(!mp[x].count(c.first))
                mp[x][c.first]=c.second;
            else
                _min(mp[x][c.first],c.second);
        }
    };
    function<void(int,int,int,int)>dfs=[&](int nod,int tt,int h,int sum)
    {
        mp[nod][sum]=h;
        for(auto &c:g[nod])
        {
            if(c.first==tt)
                continue;
            dfs(c.first,nod,h+1,sum+c.second);
            merge(nod,c.first,h,sum);
        }
    };
    dfs(0,0,0,0);
    if(rez==n+1)
        return -1;
    return rez;
}
/*int g[100][2],h[100];
void solve()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n-1;i++)
    {
        cin>>g[i][0]>>g[i][1];
    }
    for(int i=0;i<n-1;i++)
    {
        cin>>h[i];
    }
    cout<<best_path(n,k,g,h);


}
main()
{
    i32 tt=1;
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cin>>tt;
    while(tt--)
    {
        solve();
    }
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 592 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 122 ms 23880 KB Output is correct
20 Correct 106 ms 23844 KB Output is correct
21 Correct 93 ms 23596 KB Output is correct
22 Correct 107 ms 23296 KB Output is correct
23 Correct 134 ms 32872 KB Output is correct
24 Correct 103 ms 25844 KB Output is correct
25 Correct 74 ms 25884 KB Output is correct
26 Correct 47 ms 33568 KB Output is correct
27 Correct 136 ms 38476 KB Output is correct
28 Correct 232 ms 75992 KB Output is correct
29 Correct 251 ms 74212 KB Output is correct
30 Correct 185 ms 38508 KB Output is correct
31 Correct 137 ms 38572 KB Output is correct
32 Correct 194 ms 38608 KB Output is correct
33 Correct 178 ms 42008 KB Output is correct
34 Correct 288 ms 65896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 592 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 122 ms 23880 KB Output is correct
40 Correct 106 ms 23844 KB Output is correct
41 Correct 93 ms 23596 KB Output is correct
42 Correct 107 ms 23296 KB Output is correct
43 Correct 134 ms 32872 KB Output is correct
44 Correct 103 ms 25844 KB Output is correct
45 Correct 74 ms 25884 KB Output is correct
46 Correct 47 ms 33568 KB Output is correct
47 Correct 136 ms 38476 KB Output is correct
48 Correct 232 ms 75992 KB Output is correct
49 Correct 251 ms 74212 KB Output is correct
50 Correct 185 ms 38508 KB Output is correct
51 Correct 137 ms 38572 KB Output is correct
52 Correct 194 ms 38608 KB Output is correct
53 Correct 178 ms 42008 KB Output is correct
54 Correct 288 ms 65896 KB Output is correct
55 Correct 11 ms 3412 KB Output is correct
56 Correct 6 ms 2388 KB Output is correct
57 Correct 59 ms 21936 KB Output is correct
58 Correct 39 ms 17084 KB Output is correct
59 Correct 68 ms 38272 KB Output is correct
60 Correct 277 ms 74872 KB Output is correct
61 Correct 162 ms 40972 KB Output is correct
62 Correct 129 ms 38428 KB Output is correct
63 Correct 186 ms 38500 KB Output is correct
64 Correct 461 ms 79572 KB Output is correct
65 Correct 403 ms 77900 KB Output is correct
66 Correct 255 ms 70024 KB Output is correct
67 Correct 156 ms 34116 KB Output is correct
68 Correct 298 ms 50684 KB Output is correct
69 Correct 355 ms 54532 KB Output is correct
70 Correct 253 ms 48520 KB Output is correct