# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
241434 |
2020-06-24T07:43:06 Z |
Vimmer |
Mag (COCI16_mag) |
C++14 |
|
4000 ms |
121180 KB |
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 1000001
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9
using namespace std;
//using namespace __gnu_pbds;
const long long CUR = 60000000;
typedef long double ld;
typedef long long ll;
typedef short int si;
typedef array <int, 3> a3;
//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int a[N], kol[N];
ld ans = -1;
ll l, r, mt;
vector <int> g[N];
bool cmp(int x, int y)
{
if (a[x] != a[y]) return a[x] < a[y];
return kol[x] < kol[y];
}
inline void dfs(int v, int p, int kol, ll sum)
{
mt++;
ll sumr = sum;
sum *= ll(a[v]);
if (sum < sumr) return;
if (sum > 1e9) return;
ld res = ld(ld(sum) / ld(kol));
if (ans < 0 || ans - res > 0)
{
ans = res;
l = sum; r = kol;
}
for (auto it : g[v])
{
if (mt > CUR) return;
if (it == p) continue;
dfs(it, v, kol + 1, sum);
}
}
int main()
{
//freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin >> n;
vector <int> gr; gr.clear();
for (int i = 1; i < n; i++)
{
int x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
for (int i = 1; i <= n; i++) {gr.pb(i); cin >> a[i];}
for (int i = 1; i <= n; i++)
{
int koler = 0;
for (auto it : g[i]) if (a[it] == 1) koler++;
kol[i] = koler;
}
sort(gr.begin(), gr.end(), cmp);
for (int i = 0; i < n && mt < CUR; i++) dfs(gr[i], -1, 1, 1);
cout << l << "/" << r << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
23808 KB |
Output is correct |
2 |
Correct |
22 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
23936 KB |
Output is correct |
2 |
Correct |
36 ms |
23936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1808 ms |
121180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
23808 KB |
Output is correct |
2 |
Correct |
1226 ms |
66856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2029 ms |
106828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1125 ms |
66912 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
949 ms |
67928 KB |
Output is correct |
2 |
Execution timed out |
4062 ms |
28400 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4067 ms |
28400 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1157 ms |
64576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1651 ms |
67420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |