답안 #83100

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
83100 2018-11-05T10:07:47 Z luckyboy Mag (COCI16_mag) C++14
12 / 120
55 ms 23252 KB
/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 100005
#define maxm 500005
#define pii pair <int,int>
#define Task "Mag"
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
int n,val[maxn],dp[maxn][2];
vector <int> a[maxn];
pair <long long,long long> ans = mp(maxc,1);
void Dfs(int u,int par)
{
    for (int v : a[u])
        if (v != par)
        {
            Dfs(v,u);
            if (dp[u][0] < dp[v][0])
            {
                dp[u][1] = dp[u][0];
                dp[u][0] = dp[v][0];
            }
            else dp[u][1] = max(dp[u][1],dp[v][0]);
        }
    if (val[u] == 1) ++dp[u][0];
    else dp[u][0] = dp[u][1] = 0;
}
int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen(Task".inp", "r",stdin);
    //freopen(Task".out", "w",stdout);
    read(n);
    FOR(i,1,n-1)
    {
        int x,y;
        read(x),read(y);
        a[x].pb(y);
        a[y].pb(x);
    }
    ans.S = 1;
    FOR(i,1,n) read(val[i]),ans.F = min(ans.F,1ll*val[i]);
    Dfs(1,0);
    FOR(i,1,n)
        if (dp[i][0] + dp[i][1] > 1)
        {
             if (ans.F == 1)
             {
                 ans.S = max(ans.S,1ll*dp[i][0] + dp[i][1]);
             }
             else ans = mp(1,dp[i][0] + dp[i][1]);
        }
    long long temp = __gcd(ans.F,ans.S);
    ans.F /= temp,ans.S /= temp;
    writep(ans.F);
    putchar('/');
    write(ans.S);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 3076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 5604 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 5660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 55 ms 19548 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 19548 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 19548 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 19548 KB Output is correct
2 Runtime error 7 ms 19548 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 19548 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 52 ms 23252 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -