Submission #519687

#TimeUsernameProblemLanguageResultExecution timeMemory
519687Killer2501Mag (COCI16_mag)C++14
24 / 120
5 ms876 KiB
#include <bits/stdc++.h> #define ll long long #define ld double #define ull unsigned long long #define pb push_back #define pll pair<ll, ll> #define pii pair<int, int> #define fi first #define se second using namespace std; const int N = 1e3+5; const int M = 1e2+2; const ll base = 1e4; const ll mod = 998244353; const int inf = 1e9; const double ex = 1e-9; int k, t, n; int a[N], b[N], tong, m, ans; pii mx[N]; vector<int> vi, adj[N]; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); double p[N][N], res[N], q[N]; void upd(int u, int x) { if(x > mx[u].fi)mx[u].fi = x; else if(x > mx[u].se)mx[u].se = x; } void dfs(int u, int p = 0) { for(int v: adj[u]) { if(v == p)continue; dfs(v, u); if(a[v] == 1)upd(u, mx[v].fi+1); } } void dfs1(int u, int p = 0) { for(int v: adj[u]) { if(v == p)continue; if(a[u] == 1) { if(mx[u].fi != mx[v].fi+1)upd(v, mx[u].fi+1); else upd(v, mx[u].se+1); } dfs1(v, u); } } void sol(int icase) { cin >> n; for(int i = 1; i < n; i ++) { int x, y; cin >> x >> y; adj[x].pb(y); adj[y].pb(x); } for(int i = 1; i <= n; i ++)cin >> a[i]; dfs(1); dfs1(1); pii res; res.fi = inf; res.se = 1; for(int u = 1; u <= n; u ++) { //cout << a[u] <<" "<<mx[u].fi<<" "<<mx[u].se<<'\n'; if(1ll * res.fi * (mx[u].fi+mx[u].se+1) > 1ll * a[u] * res.se) { res.fi = a[u]; res.se = mx[u].se+mx[u].fi+1; } } k = __gcd(res.fi, res.se); res.fi /= k; res.se /= k; cout << res.fi <<"/"<<res.se; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); #define task "test" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int test = 1; //cin >> test; for(int i = 1; i <= test; i ++)sol(i); return 0; }

Compilation message (stderr)

mag.cpp: In function 'int main()':
mag.cpp:90:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mag.cpp:91:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...