# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
156131 |
2019-10-03T15:13:39 Z |
vex |
Mag (COCI16_mag) |
C++14 |
|
610 ms |
262148 KB |
/** 16:14 **/
#include <bits/stdc++.h>
#define maxn 1000005
#define INF 2000000000
#define ll long long
#define pll pair<ll,ll>
#define gore first
#define dole second
#define qINF {maxn,1}
using namespace std;
const int Gre2 = 2;
int n;
int a[maxn];
vector<int>adj[maxn];
pll manji(pll q1,pll q2)
{
bool t=(q1.gore*q2.dole<=q2.gore*q1.dole);
if(t)return q1;
return q2;
}
pll dp[maxn][22][2];
void dfs(int v,int p)
{
for(int i=0;i<=Gre2;i++)
{
dp[v][i][0]=dp[v][i][1]=qINF;
}
for(auto x:adj[v])
{
if(x==p)continue;
dfs(x,v);
for(int i=0;i<=Gre2;i++)
{
if( manji(dp[v][i][0],dp[x][i][0])==dp[x][i][0] )
{
dp[v][i][1]=dp[v][i][0];
dp[v][i][0]=dp[x][i][0];
}
else if( manji(dp[v][i][1],dp[x][i][0])==dp[x][i][0] )
{
dp[v][i][1]=dp[x][i][0];
}
}
}
for(int i=0;i<=Gre2;i++)
{
dp[v][i][0].dole++;
dp[v][i][1].dole++;
dp[v][i][0].gore*=a[v];
dp[v][i][1].gore*=a[v];
if(dp[v][i][0].gore>=dp[v][i][0].dole)dp[v][i][0]=qINF;
if(dp[v][i][1].gore>=dp[v][i][1].dole)dp[v][i][1]=qINF;
}
if (a[v]!=1)
{
dp[v][0][0]=qINF;
dp[v][0][1]=qINF;
for(int i=Gre2;i>0;i--)
{
dp[v][i][0]=dp[v][i-1][0];
dp[v][i][1]=dp[v][i-1][1];
}
}
else
{
dp[v][0][0]=manji(dp[v][0][0],{1,1});
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n;
for(int i=1;i<n;i++)
{
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
int najm=INF;
for(int i=1;i<=n;i++)
{
cin>>a[i];
najm=min(a[i],najm);
}
if(najm>1)
{
cout<<najm<<"/1";
return 0;
}
dfs(1,1);
pll sol={1,1};
for(int v=1;v<=n;v++)
{
//cout<<v<<" ";
for(int i=0;i<=Gre2;i++)
{
//cout<<dp[v][i][0].gore<<"/"<<dp[v][i][0].dole<<","<<dp[v][i][1].gore<<"/"<<dp[v][i][1].dole<<" ";
sol=manji(sol,dp[v][i][0]);
for(int j=0;i+j<=Gre2;j++)
{
int ind1=0,ind2=0;
if(i==j)ind2=1;
pll tre;
tre.gore=dp[v][i][ind1].gore*dp[v][j][ind2].gore/a[v];
tre.dole=dp[v][i][ind1].dole+dp[v][j][ind2].dole-1;
if(tre.gore>=tre.dole)continue;
/*if(manji(sol,tre)==tre)
{
cout<<i<<","<<j<<","<<tre.gore<<"/"<<tre.dole<<",";
cout<<dp[v][i][ind1].gore<<"/"<<dp[v][i][ind1].dole<<",";
cout<<dp[v][j][ind2].gore<<"/"<<dp[v][j][ind2].dole<<endl;
}*/
sol=manji(sol,tre);
}
}
//cout<<endl;
}
ll d=__gcd(sol.gore,sol.dole);
sol.gore/=d;
sol.dole/=d;
cout<<sol.gore<<"/"<<sol.dole;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
24056 KB |
Output is correct |
2 |
Correct |
25 ms |
24184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
24568 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
546 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
23928 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
596 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
609 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
597 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
206 ms |
97992 KB |
Output is correct |
2 |
Runtime error |
610 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
577 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
604 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |