답안 #755302

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
755302 2023-06-09T17:45:36 Z amin 경주 (Race) (IOI11_race) C++14
100 / 100
815 ms 86416 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
map<ll,ll>ma[200000];
ll pa[200000];
ll dist[200000];
ll k;
ll val[200000];
ll sz[200000];
ll ans=10000000000;
ll par(ll x)
{
    if(pa[x]==x)
        return x;
    pa[x]=par(pa[x]);
    return pa[x];
}
ll un(ll x,ll y,ll desired)
{
    ll sum=100000000000000;
    x=par(x);
    y=par(y);
    if(x==y)
        return sum;
    if(sz[y]>sz[x])
        swap(x,y);
        pa[y]=x;
        sz[x]+=sz[y];
        sz[y]=0;
     //   cout<<sz[x]<<endl;
    for(auto i:ma[y])
    {
      //  cout<<desired-i.first<<endl;
      if(i.second==0)
        continue;
        if(ma[x][desired-i.first]!=0)//beware of the root case
        {
         //   cout<<1<<endl;

            sum=min(sum,i.second+ma[x][desired-i.first]);
        }


    }for(auto i:ma[y])
    {
if(i.second==0)
    continue;
if(ma[x][i.first]==0)
    ma[x][i.first]=i.second;
else
        ma[x][i.first]=min(i.second,ma[x][i.first]);
    }
    ma[y].clear();
    return sum;
}
vector<ll>v[200000],w[200000];
void dfs(ll in,ll pa)
{
    for(ll y=0;y<v[in].size();y++)
    {
        ll i=v[in][y];
        ll h=w[in][y];
        if(i==pa)
            continue;
            dist[i]=dist[in]+1;
            val[i]=val[in]+h;
        dfs(i,in);
    }

}
void solve(ll in,ll pa)
{

    ma[in][val[in]]=dist[in];
   // cout<<dist[in]<<endl;
    ll z=10000000000;
    for(auto i:v[in])
    {
        if(i==pa)
            continue;
        solve(i,in);
        //z=min(z,un(in,i,k+2*(val[in])));



    }
    for(auto i:v[in])
    {
        if(i==pa)
            continue;

        z=min(z,un(in,i,k+2*(val[in])));



    }

   // cout<<in<<' '<<z<<endl;
    ans=min(ans,z-2*dist[in]);
}
int best_path(int N, int K, int H[][2], int L[])
{
    ll n=N;
   k=K;

  for(ll i=0;i<n;i++)
  {
    ll x=H[i][0];
    ll y=H[i][1];
    v[x].push_back(y);
    v[y].push_back(x);
    w[x].push_back(L[i]);
    w[y].push_back(L[i]);
  }
  dist[0]=1;
  dfs(0,0);
  for(ll i=0;i<n;i++)
  {
      pa[i]=i;
      sz[i]=1;
  }

solve(0,0);/*
for(ll i=0;i<n;i++)
{
   // cout<<ma[i].size()<<' '<<sz[i];
    for(auto z:ma[i])
    {
        cout<<z.first<<' '<<z.second<<endl;
    }

}
cout<<endl;
cout<<ans<<endl;*/
if(ans>1000000)
    return -1;
else
return ans;
}

Compilation message

race.cpp: In function 'long long int un(long long int, long long int, long long int)':
race.cpp:26:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   26 |     if(sz[y]>sz[x])
      |     ^~
race.cpp:28:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   28 |         pa[y]=x;
      |         ^~
race.cpp:35:7: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   35 |       if(i.second==0)
      |       ^~
race.cpp:37:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   37 |         if(ma[x][desired-i.first]!=0)//beware of the root case
      |         ^~
race.cpp: In function 'void dfs(long long int, long long int)':
race.cpp:60:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for(ll y=0;y<v[in].size();y++)
      |                ~^~~~~~~~~~~~~
race.cpp:64:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   64 |         if(i==pa)
      |         ^~
race.cpp:66:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   66 |             dist[i]=dist[in]+1;
      |             ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19156 KB Output is correct
2 Correct 10 ms 19096 KB Output is correct
3 Correct 13 ms 19156 KB Output is correct
4 Correct 11 ms 19100 KB Output is correct
5 Correct 12 ms 19100 KB Output is correct
6 Correct 13 ms 19028 KB Output is correct
7 Correct 11 ms 19156 KB Output is correct
8 Correct 10 ms 19156 KB Output is correct
9 Correct 13 ms 19156 KB Output is correct
10 Correct 10 ms 19100 KB Output is correct
11 Correct 9 ms 19064 KB Output is correct
12 Correct 10 ms 19156 KB Output is correct
13 Correct 10 ms 19100 KB Output is correct
14 Correct 12 ms 19108 KB Output is correct
15 Correct 10 ms 19084 KB Output is correct
16 Correct 11 ms 19156 KB Output is correct
17 Correct 10 ms 19156 KB Output is correct
18 Correct 10 ms 19040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19156 KB Output is correct
2 Correct 10 ms 19096 KB Output is correct
3 Correct 13 ms 19156 KB Output is correct
4 Correct 11 ms 19100 KB Output is correct
5 Correct 12 ms 19100 KB Output is correct
6 Correct 13 ms 19028 KB Output is correct
7 Correct 11 ms 19156 KB Output is correct
8 Correct 10 ms 19156 KB Output is correct
9 Correct 13 ms 19156 KB Output is correct
10 Correct 10 ms 19100 KB Output is correct
11 Correct 9 ms 19064 KB Output is correct
12 Correct 10 ms 19156 KB Output is correct
13 Correct 10 ms 19100 KB Output is correct
14 Correct 12 ms 19108 KB Output is correct
15 Correct 10 ms 19084 KB Output is correct
16 Correct 11 ms 19156 KB Output is correct
17 Correct 10 ms 19156 KB Output is correct
18 Correct 10 ms 19040 KB Output is correct
19 Correct 11 ms 19088 KB Output is correct
20 Correct 10 ms 19028 KB Output is correct
21 Correct 13 ms 19284 KB Output is correct
22 Correct 12 ms 19284 KB Output is correct
23 Correct 14 ms 19284 KB Output is correct
24 Correct 11 ms 19296 KB Output is correct
25 Correct 11 ms 19368 KB Output is correct
26 Correct 11 ms 19284 KB Output is correct
27 Correct 11 ms 19204 KB Output is correct
28 Correct 12 ms 19284 KB Output is correct
29 Correct 12 ms 19400 KB Output is correct
30 Correct 12 ms 19316 KB Output is correct
31 Correct 12 ms 19284 KB Output is correct
32 Correct 11 ms 19364 KB Output is correct
33 Correct 12 ms 19308 KB Output is correct
34 Correct 11 ms 19284 KB Output is correct
35 Correct 14 ms 19380 KB Output is correct
36 Correct 11 ms 19284 KB Output is correct
37 Correct 12 ms 19284 KB Output is correct
38 Correct 14 ms 19312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19156 KB Output is correct
2 Correct 10 ms 19096 KB Output is correct
3 Correct 13 ms 19156 KB Output is correct
4 Correct 11 ms 19100 KB Output is correct
5 Correct 12 ms 19100 KB Output is correct
6 Correct 13 ms 19028 KB Output is correct
7 Correct 11 ms 19156 KB Output is correct
8 Correct 10 ms 19156 KB Output is correct
9 Correct 13 ms 19156 KB Output is correct
10 Correct 10 ms 19100 KB Output is correct
11 Correct 9 ms 19064 KB Output is correct
12 Correct 10 ms 19156 KB Output is correct
13 Correct 10 ms 19100 KB Output is correct
14 Correct 12 ms 19108 KB Output is correct
15 Correct 10 ms 19084 KB Output is correct
16 Correct 11 ms 19156 KB Output is correct
17 Correct 10 ms 19156 KB Output is correct
18 Correct 10 ms 19040 KB Output is correct
19 Correct 179 ms 31172 KB Output is correct
20 Correct 162 ms 32212 KB Output is correct
21 Correct 184 ms 32276 KB Output is correct
22 Correct 169 ms 32368 KB Output is correct
23 Correct 260 ms 33276 KB Output is correct
24 Correct 178 ms 32940 KB Output is correct
25 Correct 146 ms 38704 KB Output is correct
26 Correct 77 ms 45080 KB Output is correct
27 Correct 321 ms 57280 KB Output is correct
28 Correct 342 ms 83972 KB Output is correct
29 Correct 353 ms 84616 KB Output is correct
30 Correct 322 ms 57292 KB Output is correct
31 Correct 316 ms 57448 KB Output is correct
32 Correct 379 ms 58460 KB Output is correct
33 Correct 356 ms 44168 KB Output is correct
34 Correct 594 ms 70560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19156 KB Output is correct
2 Correct 10 ms 19096 KB Output is correct
3 Correct 13 ms 19156 KB Output is correct
4 Correct 11 ms 19100 KB Output is correct
5 Correct 12 ms 19100 KB Output is correct
6 Correct 13 ms 19028 KB Output is correct
7 Correct 11 ms 19156 KB Output is correct
8 Correct 10 ms 19156 KB Output is correct
9 Correct 13 ms 19156 KB Output is correct
10 Correct 10 ms 19100 KB Output is correct
11 Correct 9 ms 19064 KB Output is correct
12 Correct 10 ms 19156 KB Output is correct
13 Correct 10 ms 19100 KB Output is correct
14 Correct 12 ms 19108 KB Output is correct
15 Correct 10 ms 19084 KB Output is correct
16 Correct 11 ms 19156 KB Output is correct
17 Correct 10 ms 19156 KB Output is correct
18 Correct 10 ms 19040 KB Output is correct
19 Correct 11 ms 19088 KB Output is correct
20 Correct 10 ms 19028 KB Output is correct
21 Correct 13 ms 19284 KB Output is correct
22 Correct 12 ms 19284 KB Output is correct
23 Correct 14 ms 19284 KB Output is correct
24 Correct 11 ms 19296 KB Output is correct
25 Correct 11 ms 19368 KB Output is correct
26 Correct 11 ms 19284 KB Output is correct
27 Correct 11 ms 19204 KB Output is correct
28 Correct 12 ms 19284 KB Output is correct
29 Correct 12 ms 19400 KB Output is correct
30 Correct 12 ms 19316 KB Output is correct
31 Correct 12 ms 19284 KB Output is correct
32 Correct 11 ms 19364 KB Output is correct
33 Correct 12 ms 19308 KB Output is correct
34 Correct 11 ms 19284 KB Output is correct
35 Correct 14 ms 19380 KB Output is correct
36 Correct 11 ms 19284 KB Output is correct
37 Correct 12 ms 19284 KB Output is correct
38 Correct 14 ms 19312 KB Output is correct
39 Correct 179 ms 31172 KB Output is correct
40 Correct 162 ms 32212 KB Output is correct
41 Correct 184 ms 32276 KB Output is correct
42 Correct 169 ms 32368 KB Output is correct
43 Correct 260 ms 33276 KB Output is correct
44 Correct 178 ms 32940 KB Output is correct
45 Correct 146 ms 38704 KB Output is correct
46 Correct 77 ms 45080 KB Output is correct
47 Correct 321 ms 57280 KB Output is correct
48 Correct 342 ms 83972 KB Output is correct
49 Correct 353 ms 84616 KB Output is correct
50 Correct 322 ms 57292 KB Output is correct
51 Correct 316 ms 57448 KB Output is correct
52 Correct 379 ms 58460 KB Output is correct
53 Correct 356 ms 44168 KB Output is correct
54 Correct 594 ms 70560 KB Output is correct
55 Correct 32 ms 21196 KB Output is correct
56 Correct 20 ms 20444 KB Output is correct
57 Correct 98 ms 32644 KB Output is correct
58 Correct 71 ms 38516 KB Output is correct
59 Correct 132 ms 51080 KB Output is correct
60 Correct 408 ms 83924 KB Output is correct
61 Correct 360 ms 61912 KB Output is correct
62 Correct 325 ms 58380 KB Output is correct
63 Correct 383 ms 58568 KB Output is correct
64 Correct 722 ms 63680 KB Output is correct
65 Correct 815 ms 72792 KB Output is correct
66 Correct 402 ms 86416 KB Output is correct
67 Correct 262 ms 59356 KB Output is correct
68 Correct 559 ms 70056 KB Output is correct
69 Correct 619 ms 77720 KB Output is correct
70 Correct 530 ms 68164 KB Output is correct