이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define bn binary_search
#define sz(x) int((x).size())
#define lz(x) long long((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 1000000007
#define pfx(x) partial_sum(all(x),(x).begin())
#define sfx(x) partial_sum(rall(x),(x).rbegin())
#define minl(x) min_element(all(x))
#define maxl(x) max_element(all(x))
#define itn(x,y) iota(all(x),y)
#define accu(x,y) accumulate(all(x),y)
#define yes cout<<"Y"<<"E"<<"S"<<endl
#define no cout<<"N"<<"O"<<endl
#define mx INT_MAX
#define mn INT_MIN
#define lin(x) for(int i=0;i<sz(x);i++) cin>>x[i]
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ll> vl;
typedef pair<ll,ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<pair<int,ii>> gw;
typedef vector<pair<ll,il>> lw;
typedef vector<vc> vvc;
vector<vii> lmao;
vb vis;
int dfs(int u,int pes,int cock, int k){
for(auto v : lmao[u]){
if(vis[v.F]) return cock;
vis[v.F]=true;
pes+=v.S;
cock++;
if(pes==k){
return cock;
}
if(pes<k){
return dfs(v.F,pes,cock,k);
}
if(pes>k){
return mx;
}
}
return cock;
}
int best_path(int n,int k, int h[][2], int l[]){
lmao.assign(n,vii());
vis.assign(n,false);
for(int i=0;i<n-1;i++){
lmao[h[i][0]].pb({h[i][1],l[i]});
lmao[h[i][1]].pb({h[i][0],l[i]});
}
int ans=mx;
for(int i=0;i<n;i++){
ans=min(ans,dfs(i,0,0,k));
vis.assign(n,false);
}
if(ans==mx) return -1;
return ans;
}
/*int main(){
int n,k;
cin>>n>>k;
int h[n-1][2];
for(int i=0;i<n-1;i++){
cin>>h[i][0]>>h[i][1];
}
int l[n-1];
for(int i=0;i<n-1;i++) cin>>l[i];
cout<<best_path(n,k,h,l)<<endl;
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |