Submission #83100

#TimeUsernameProblemLanguageResultExecution timeMemory
83100luckyboyMag (COCI16_mag)C++14
12 / 120
55 ms23252 KiB
/**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; }
#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...