#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a));
#define all(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
vp edges[100005];
int n, m;
ll dfs(int x, int p) {
ll minn = LMAX, secondmin = LMAX;
for (auto edge: edges[x]) {
if (edge.fi != p) {
ll child = dfs(edge.fi, x) + edge.se;
if (child < minn) {
secondmin = minn;
minn = child;
} else if (child < secondmin) {
secondmin = child;
}
}
}
if (edges[x].size() == 1) {
return 0;
}
return secondmin;
}
int travel_plan(int N, int M, int r[][2], int l[], int K, int P[]) {
n = N;
m = M;
FOR(i, 0, m-1) {
edges[r[i][0]].emplace_back(r[i][1], l[i]);
edges[r[i][1]].emplace_back(r[i][0], l[i]);
}
return dfs(0, -1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2688 KB |
Output is correct |
5 |
Correct |
3 ms |
2688 KB |
Output is correct |
6 |
Correct |
3 ms |
2688 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2688 KB |
Output is correct |
5 |
Correct |
3 ms |
2688 KB |
Output is correct |
6 |
Correct |
3 ms |
2688 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
9 |
Runtime error |
196 ms |
262148 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2688 KB |
Output is correct |
5 |
Correct |
3 ms |
2688 KB |
Output is correct |
6 |
Correct |
3 ms |
2688 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
9 |
Runtime error |
196 ms |
262148 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |