#pragma GCC optimize "-O3"
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include "race.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define NumberOfOnes __builtin_popcount
#define LSOne(S) (S & (-S))
#define ll long long
#define two pair<int,int>
#define twoll pair<ll,ll>
#define four pair<two,two>
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define y1 y1922
#define INF 1000000000000000000
#define P 1000000007
#define lmax 1000000000
#define nn 1000003
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define vi vector<int>
#define vll vector<ll>
#define vtwo vector<two>
#define ALL(container) (container).begin(), (container).end()
#define sz(container) (int)(container.size())
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mid(a,b) (a+b>>1)
#define minN 0
#define maxN 10000000
#define na(x) ((x)<P?(x):(x)-P)
#define ab(a) (-(a)<(a)?(a):-(a))
#define FAST std::ios::sync_with_stdio(false)
#define xRand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rnd rng
#define IT iterator
typedef
tree<
int,// aq pair<int,int> shegidzlia
null_type,
less/*_equal*/<int>,// aqac
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// '_equal' mashin ginda roca multiset gchirdeba
template<class key, class value,class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
ordered_map<int, int> my_map;
inline int rin(){
int x=0,w=1;char ch=getchar();
while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
if (ch=='-') w=0,ch=getchar();
while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return w?x:-x;
}
inline int bin(){
int x=0;char ch=getchar();
while (ch<'0'||ch>'9') ch=getchar();
while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return x;
}
const int mr=200004;
int sus[mr],n,k,fx[mr],a,b,c,ans,mp1[mr],mp[mr];
vector<two>v[mr];
two sav;
void go(int sad,int saidan,int size,int ¢re){
sus[sad]=1;
for(auto i:v[sad]){
if(fx[i.f]!=0||i.f==saidan) continue;
go(i.f,sad,size,centre);
sus[sad]+=sus[i.f];
}
if((sus[sad]*2>=size||saidan==-1)&¢re==-1) centre=sad;
}
void rec(int sad,int saidan,int tye){
if(sav.f==k) ans=min(ans,sav.s);
if(sav.f>=k) return ;
if(tye==1){
mp1[sav.f]=min(mp1[sav.f],sav.s);
ans=min(ans,mp1[sav.f]+mp[k-sav.f]);
}else
if(tye==2){
mp[sav.f]=min(mp[sav.f],mp1[sav.f]);
mp1[sav.f]=lmax;
}else mp[sav.f]=lmax;
for(auto j:v[sad]){
if(fx[j.f]==0&&j.f!=saidan){
sav.f+=j.s; sav.s++;
rec(j.f,sad,tye);
sav.f-=j.s; sav.s--;
}
}
}
void work(int s,int size){
int centre;
go(s,-1,size,centre);
fx[s]=1;
for(auto i:v[s]){
if(fx[i.f]==0){
sav.f=i.s; sav.s=1;
rec(i.f,centre,1);
rec(i.f,centre,2);
sav.f=0; sav.s=0;
}
}
rec(centre,-1,19);
for(auto i:v[s]){
if(fx[i.f]==0){
work(i.f,size/2);
}
}
}
int best_path(int N, int K, int H[][2], int L[]){
n=N,k=K;
for (int i=0; i<n-1; i++) {
v[H[i][0]].push_back({H[i][1],L[i]});
v[H[i][1]].push_back({H[i][0],L[i]});
}
ans=n+3;
for(int i=0;i<=n;i++){
mp[i]=mp1[i]=lmax;
}
work(1,n);
if(ans==n+3){
ans=-1;
}
return ans;
}
/*
* *
* * * *
* * * *
* * * *
* * * * *
* * * *
* * * *
* * *
* *
*/
Compilation message
race.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization ("unroll-loops")
race.cpp: In function 'void work(int, int)':
race.cpp:81:37: warning: 'centre' may be used uninitialized in this function [-Wmaybe-uninitialized]
if((sus[sad]*2>=size||saidan==-1)&¢re==-1) centre=sad;
^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |