Submission #579114

#TimeUsernameProblemLanguageResultExecution timeMemory
579114epicci23Mag (COCI16_mag)C++17
0 / 120
4069 ms262144 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...