#include <bits/stdc++.h>
using namespace std;
struct node {
vector<pair<node*, int>> l;
long long f = -1;
bool g = false;
};
void gfs(node* n, node* p){
for(auto [c, co] : n->l){
if(c!=p){gfs(c, n);
n->g |= c->g;}
}
}
void dfs(node* n, node* p){
for(auto [c, co] : n->l){
if(c != p){
c->f = n->f + co;
dfs(c, n);
}
}
}
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr){
node g[N];
g[0].g =true;
for(int i = 0;i < M;i++){
g[x[i]].l.emplace_back(&g[y[i]], c[i]);
g[y[i]].l.emplace_back(&g[x[i]], c[i]);
}
g[H].f = 0;
gfs(&g[H], NULL);
for(auto [c, co] : g[H].l){
if(c->g) {
c->f = co;
dfs(c, &g[H]);
}
}
long long ans = g[0].f;
for(int i = 0;i < N;i++){
if(!arr[i] && g[i].f != -1) ans = min(ans, g[i].f);
}
return ans;
}
// int main(){
// cout << solve(3, 2, 30, 2, {1, 2}, {2, 0}, {12, 4}, {1, 2, 1}) << '\n';
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
830 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
852 KB |
Correct. |
2 |
Correct |
20 ms |
1228 KB |
Correct. |
3 |
Correct |
19 ms |
1136 KB |
Correct. |
4 |
Correct |
20 ms |
1176 KB |
Correct. |
5 |
Correct |
20 ms |
1216 KB |
Correct. |
6 |
Correct |
17 ms |
2188 KB |
Correct. |
7 |
Correct |
21 ms |
2208 KB |
Correct. |
8 |
Correct |
9 ms |
3004 KB |
Correct. |
9 |
Correct |
19 ms |
1076 KB |
Correct. |
10 |
Correct |
18 ms |
1084 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1212 KB |
Correct. |
2 |
Correct |
19 ms |
1236 KB |
Correct. |
3 |
Correct |
18 ms |
1292 KB |
Correct. |
4 |
Correct |
19 ms |
688 KB |
Correct. |
5 |
Correct |
19 ms |
1100 KB |
Correct. |
6 |
Correct |
4 ms |
1364 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
9036 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
844 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
937 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
895 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
922 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |