# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1030545 | 2024-07-22T06:40:22 Z | 김은성(#10955) | Designated Cities (JOI19_designated_cities) | C++17 | 2000 ms | 35104 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll ans[200009]; bool ch[200009]; const ll INF = 0x3fffffffffffffff; vector<pair<int, ll> > graph[200009]; vector<pair<int, ll> > tree[200009]; ll depth[200009], sum = 0; int par[200009]; void construct_tree(int v){ ch[v] = 1; for(int i=0; i<graph[v].size(); i++){ int u = graph[v][i].first; if(!ch[u]){ sum += graph[v][i].second; tree[v].push_back(graph[v][i]); par[u] = v; construct_tree(u); } } } int deepest_vertex(int v, ll d){ depth[v] = d; ch[v] = 1; int ans = v; for(int i=0; i<tree[v].size(); i++){ int u = tree[v][i].first; if(!ch[u]){ int x = deepest_vertex(u, d+tree[v][i].second); if(depth[x] > depth[ans]) ans = x; } } return ans; } void delete_edge(int v, int r){ int p = par[v]; while(v != r){ for(int i=0; i<tree[p].size(); i++){ if(tree[p][i].first == v) tree[p][i].second = 0; } v = p; p = par[v]; } } int main(){ int n, i, j, a, b, q, v; ll c, d; scanf("%d", &n); for(i=1; i<n; i++){ scanf("%d %d %lld %lld", &a, &b, &c, &d); graph[a].push_back(make_pair(b, c)); graph[b].push_back(make_pair(a, d)); } for(i=1; i<=n; i++) ans[i] = INF; for(i=1; i<=n; i++){ for(j=1; j<=n; j++){ tree[j].clear(); ch[j] = 0; } sum = 0; construct_tree(i); ans[1] = min(ans[1], sum); if(graph[i].size() > 1) continue; for(j=1; j<=n; j++){ ans[j] = min(ans[j], sum); for(int k=1; k<=n; k++) ch[k]=0; int v = deepest_vertex(i, 0); sum -= depth[v]; delete_edge(v, i); } } scanf("%d", &q); while(q--){ scanf("%d", &v); printf("%lld\n", ans[v]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 9820 KB | Output is correct |
2 | Correct | 4 ms | 9820 KB | Output is correct |
3 | Correct | 4 ms | 9848 KB | Output is correct |
4 | Correct | 4 ms | 9684 KB | Output is correct |
5 | Correct | 3 ms | 9820 KB | Output is correct |
6 | Correct | 4 ms | 9820 KB | Output is correct |
7 | Correct | 4 ms | 9820 KB | Output is correct |
8 | Correct | 4 ms | 9860 KB | Output is correct |
9 | Correct | 4 ms | 9820 KB | Output is correct |
10 | Correct | 4 ms | 9624 KB | Output is correct |
11 | Correct | 4 ms | 9820 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 9820 KB | Output is correct |
2 | Execution timed out | 2086 ms | 35104 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 9816 KB | Output is correct |
2 | Execution timed out | 2087 ms | 35068 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 9820 KB | Output is correct |
2 | Correct | 4 ms | 9820 KB | Output is correct |
3 | Correct | 4 ms | 9848 KB | Output is correct |
4 | Correct | 4 ms | 9684 KB | Output is correct |
5 | Correct | 3 ms | 9820 KB | Output is correct |
6 | Correct | 4 ms | 9820 KB | Output is correct |
7 | Correct | 4 ms | 9820 KB | Output is correct |
8 | Correct | 4 ms | 9860 KB | Output is correct |
9 | Correct | 4 ms | 9820 KB | Output is correct |
10 | Correct | 4 ms | 9624 KB | Output is correct |
11 | Correct | 4 ms | 9820 KB | Output is correct |
12 | Correct | 4 ms | 9816 KB | Output is correct |
13 | Execution timed out | 2070 ms | 10036 KB | Time limit exceeded |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 9820 KB | Output is correct |
2 | Execution timed out | 2086 ms | 35104 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 9820 KB | Output is correct |
2 | Correct | 4 ms | 9820 KB | Output is correct |
3 | Correct | 4 ms | 9848 KB | Output is correct |
4 | Correct | 4 ms | 9684 KB | Output is correct |
5 | Correct | 3 ms | 9820 KB | Output is correct |
6 | Correct | 4 ms | 9820 KB | Output is correct |
7 | Correct | 4 ms | 9820 KB | Output is correct |
8 | Correct | 4 ms | 9860 KB | Output is correct |
9 | Correct | 4 ms | 9820 KB | Output is correct |
10 | Correct | 4 ms | 9624 KB | Output is correct |
11 | Correct | 4 ms | 9820 KB | Output is correct |
12 | Correct | 4 ms | 9820 KB | Output is correct |
13 | Execution timed out | 2086 ms | 35104 KB | Time limit exceeded |
14 | Halted | 0 ms | 0 KB | - |