fork download
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. using namespace std;
  4. void Code_By_Mohamed_Khaled() {
  5. ios_base::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7. cout.tie(nullptr);
  8. // #ifndef ONLINE_JUDGE
  9. // freopen("input.txt", "r", stdin);
  10. // freopen("output.txt", "w", stdout);
  11. // #endif
  12. }
  13. const ll mod=1e9+7;
  14. ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
  15. ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
  16. ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
  17. // double a;string s;ll N;map<string,vector<ll>>m_base,m_quote;
  18. // vector<map<string,double>>dp;vector<string>base,quote;vector<double>p;
  19. // double sol(ll idx,string &cur) {
  20. // if (idx==N) {
  21. // return (cur==s ? 1.0:0.0);
  22. // }
  23. // auto it=dp[idx].find(cur);
  24. // if (it!=dp[idx].end()) return it->second;
  25. // double best=(cur==s ? 1.0:0.0);
  26. // auto vec=lower_bound(m_base[cur].begin(),m_base[cur].end(), idx);
  27. // while (vec!=m_base[cur].end()) {
  28. // int j=*vec;
  29. // double val=p[j]*sol(j+1,quote[j]);
  30. // best=max(best,val);
  31. // ++vec;
  32. // }
  33. // auto index=lower_bound(m_quote[cur].begin(),m_quote[cur].end(), idx);
  34. // while (index!=m_quote[cur].end()) {
  35. // int j=*index;
  36. // double val=(1.0/p[j])*sol(j+1,base[j]);
  37. // best=max(best,val);
  38. // ++index;
  39. // }
  40. // return dp[idx][cur]=best;
  41. // }
  42. int main() {
  43. Code_By_Mohamed_Khaled();
  44. // freopen("crypto.in", "r", stdin);
  45. ll t;cin>>t;
  46. while (t--) {
  47. ll a,N;string s;cin>>a>>s>>N;
  48. map<string,double>dp;
  49. dp[s]=a;
  50. for (ll i=0;i<N;i++) {
  51. string b,q;double p;cin>>b>>q>>p;
  52. double bb=0,qq=0;
  53. if (dp.find(b)!=dp.end())bb=dp[b];
  54. if (dp.find(q)!=dp.end())qq=dp[q];
  55. if (bb>0) {
  56. dp[q]=max(dp[q],bb*p);
  57. }
  58. if (qq>0)dp[b]=max(dp[b],qq/p);
  59. }
  60. cout<<fixed<<setprecision(6)<<dp[s]<<"\n";
  61. }
  62. return 0;
  63. }
Success #stdin #stdout 0.01s 5320KB
stdin
1
100 BTC 9
XRP ETH 0.0006
ETH BTC 0.04
ADA ETH 0.001
XRP ETH 0.001
ETH ADA 900
ADA BTC 0.0001
BTC ETH 32
AXD GTR 10
FDS YTR 20
stdout
250.000000