#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define int long long
#define double long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define what_is(x) cerr << #x << " is " << x << endl;
const int N=1000005;
const int LOG=20;
typedef pair<int,int> pii;
typedef long long ll;
//sunlari dusun//
/*
* kodu kisaltcak fonksiyon
* cevaba binary search ya da normal bs
* segment tree / sparse table
* stack
* teklik ciftlik
* precomputation
* EN ONEMLISI OVERKILLEME
* edge case dusunr
* constraintlere bak
* indisleri kontrol et
* dp
* greedy
* sorting
* dfs bfs
* sieve
*/
pair<double,string> cnt={111111111111111111.0,""};
vector<int> v[N];
double arr[N];
vector<array<double,2>> dp(N,{-1,-1});
double dfs(int cur,int par,int carpim,int uzunluk,bool kestim)
{
if(dp[cur][kestim]!=-1) return dp[cur][kestim];
if((double)carpim/(double)uzunluk<cnt.ff)
{
cnt.ff=(double)carpim/(double)uzunluk;
string a="";
a+=to_string(carpim);
a.pb('/');
a+=to_string(uzunluk);
cnt.ss=a;
}
for(int x:v[cur])
{
if(x!=par)
{
double t1=dfs(x,cur,arr[x],1,1);
double t2=dfs(x,cur,carpim*arr[x],uzunluk+1,0);
dp[cur][kestim]=min(t1,t2);
}
}
return dp[cur][kestim];
}
void solve(){
int n;
cin >> n;
for(int i=1;i<n;i++)
{
int a,b;cin >> a >> b;
v[a].pb(b);
v[b].pb(a);
}
for(int i=1;i<=n;i++)
cin >> arr[i];
dfs(1,-1,arr[1],1,0);
cout << cnt.ss << endl;
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
cout << fixed << setprecision(15);
int t=1;//cin>> t;
while(t--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4046 ms |
55128 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4057 ms |
55176 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4045 ms |
194244 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4058 ms |
55020 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
531 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4046 ms |
117148 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
897 ms |
121432 KB |
Output is correct |
2 |
Execution timed out |
4059 ms |
61892 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4069 ms |
61772 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4035 ms |
117416 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4045 ms |
117688 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |