# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
622953 |
2022-08-04T21:20:21 Z |
inksamurai |
Mag (COCI16_mag) |
C++17 |
|
454 ms |
256728 KB |
#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3SgiE60 ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e
const int inf=1e13;
pii compare(const pii&l,const pii&r){
return l.fi*r.se<r.fi*l.se?l:r;
}
signed main(){
_3SgiE60;
int n;
cin>>n;
vec(vi) adj(n);
rep(i,n-1){
int u,v;
cin>>u>>v;
u-=1,v-=1;
adj[u].pb(v);
adj[v].pb(u);
}
vi a(n);
rep(i,n){
cin>>a[i];
}
pii pns={inf,1};
auto dfs=[&](auto self,int v,int par)->pii{
pii q={inf,1};
vec(pii) e;
for(auto &u:adj[v]){
if(u==par) continue;
pii p=self(self,u,v);
e.pb(p);
if(q.fi<=inf and q.fi*a[v]<inf/p.fi){
pii now={q.fi*p.fi*a[v],p.se+q.se+1};
// if(now.fi==1 and now.se==4) print("ho",v,u);
pns=compare(pns,now);
}
if(p.fi<=inf){
q=compare(q,p);
}
{
pii now={p.fi*a[v],p.se+1};
pns=compare(pns,now);
}
}
q={inf,1};
for(auto p:e){
q=compare(q,pii(p.fi*a[v],p.se+1));
}
pns=compare(pns,pii(a[v],1));
q=compare(q,pii(a[v],1));
return q;
};
dfs(dfs,0,-1);
int g=gcd(pns.fi,pns.se);
pns.fi/=g;
pns.se/=g;
cout<<pns.fi<<"/"<<pns.se<<"\n";
// print(pns.fi,pns.se);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
302 ms |
125488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
406 ms |
248496 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
406 ms |
244524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
332 ms |
62640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
311 ms |
73224 KB |
Output is correct |
2 |
Correct |
44 ms |
7156 KB |
Output is correct |
3 |
Correct |
454 ms |
256728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
7196 KB |
Output is correct |
2 |
Incorrect |
330 ms |
64216 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
296 ms |
62660 KB |
Output is correct |
2 |
Incorrect |
330 ms |
62164 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
330 ms |
64264 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |