# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
101565 | 2019-03-19T04:30:48 Z | cheeheng | Chase (CEOI17_chase) | C++14 | 1038 ms | 525312 KB |
#include <bits/stdc++.h> using namespace std; long long p[100005]; long long p2[100005]; vector<int> AdjList[100005]; int parent[100005]; int dist[13]; int main(){ int N, v; scanf("%d%d", &N, &v); for(int i = 1; i <= N; i ++){ scanf("%d", &p[i]); p2[i] = p[i]; } for(int i = 1; i < N; i ++){ int a, b; scanf("%d%d", &a, &b); AdjList[a].push_back(b); AdjList[b].push_back(a); } long long ans = 0; for(int i = 1; i <= N; i ++){ queue<int> q; q.push(i); memset(dist, -1, sizeof(dist)); dist[i] = 0; parent[i] = -1; while(!q.empty()){ int u = q.front(); q.pop(); for(int v: AdjList[u]){ if(dist[v] == -1){ dist[v] = dist[u] + 1; parent[v] = u; q.push(v); } } } for(int j = i; j <= N; j ++){ vector<int> path; int temp1 = j; do{ path.push_back(temp1); temp1 = parent[temp1]; }while(temp1 != -1); reverse(path.begin(), path.end()); for(int k = 1; k <= N; k ++){ p2[k] = p[k]; } int size1 = path.size(); for(int k = 0; k < (1<<size1); k ++){ int cnt = 0; long long score = 0; for(int l = 0; l < size1; l ++){ if(k&(1<<l)){ cnt ++; } } if(cnt > v){continue;} for(int l = 0; l < size1; l ++){ if(k&(1<<l)){ // drop breadcrumb long long temp = 0; for(int x: AdjList[path[l]]){ temp += p2[x]; p2[x] = 0; } score -= p2[path[l]]; p2[path[l]] = temp; }else{ // do not drop breadcrumb score -= p2[path[l]]; } } for(int l = 0; l < size1; l ++){ score += p2[path[l]]; } ans = max(ans, score); } } } printf("%lld", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1038 ms | 525312 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 2688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |