# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
331685 | BeanZ | Mag (COCI16_mag) | C++14 | 488 ms | 141824 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
const int lim = 100;
ll dp1[N], dp2[N], a[N];
vector<ll> node[N];
void upd(ll u, ll c){
dp2[u] = max(dp2[u], c);
if (dp2[u] > dp1[u]) swap(dp2[u], dp1[u]);
}
void init(ll u, ll p){
for (auto j : node[u]){
if (j == p) continue;
init(j, u);
if (a[j] == 1) upd(u, dp1[j] + 1);
}
}
void dfs(ll u, ll p){
for (auto j : node[u]){
if (j == p) continue;
if (a[u] == 1){
if ((dp1[j] + 1) == dp1[u]) upd(j, dp2[u]);
else upd(j, dp1[u]);
}
dfs(j, u);
}
}
void red(pair<ll, ll> &u, pair<ll, ll> v){
if (u.first * v.second > u.second * v.first){
u = v;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("A.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll n;
cin >> n;
for (int i = 1; i < n; i++){
ll u, v;
cin >> u >> v;
node[u].push_back(v);
node[v].push_back(u);
}
for (int i = 1; i <= n; i++) cin >> a[i];
init(1, 1);
dfs(1, 1);
pair<ll, ll> ans = {1e9, 1};
for (int i = 1; i <= n; i++){
red(ans, {a[i], dp1[i] + dp2[i] + 1});
}
ll gcd = __gcd(ans.first, ans.second);
ans.first /= gcd;
ans.second /= gcd;
cout << ans.first << "/" << ans.second;
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |