#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 dist[100005], from[100005];
bool vis[100005];
set <pii> s;
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]);
}
priority_queue <pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > pq;
FOR(i, 0, n-1) {
dist[i] = 1e15;
}
FOR(i, 0, K-1) {
dist[P[i]] = 0;
pq.push({0LL, P[i]});
}
while (!pq.empty()) {
pll f = pq.top();
pq.pop();
int u = f.se;
ll d = f.fi;
if (vis[u]) continue;
vis[u] = true;
if (dist[u] > 0) s.insert({u, from[u]});
for (auto edge: edges[u]) {
if (!vis[edge.fi] && dist[edge.fi] > dist[u] + edge.se) {
dist[edge.fi] = dist[u] + edge.se;
from[edge.fi] = u;
pq.push({dist[edge.fi], edge.fi});
}
}
}
FOR(i, 0, n-1) {
dist[i] = 1e15;
vis[i] = false;
}
FOR(i, 0, K-1) {
dist[P[i]] = 0;
pq.push({0LL, P[i]});
}
while (!pq.empty()) {
pll f = pq.top();
pq.pop();
int u = f.se;
ll d = f.fi;
if (vis[u]) continue;
vis[u] = true;
for (auto edge: edges[u]) {
if (!s.count({edge.fi, u}) && !s.count({u, edge.fi}) && !vis[edge.fi] && dist[edge.fi] > dist[u] + edge.se) {
dist[edge.fi] = dist[u] + edge.se;
from[edge.fi] = u;
pq.push({dist[edge.fi], edge.fi});
}
}
}
return dist[0];
}
Compilation message
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:67:8: warning: unused variable 'd' [-Wunused-variable]
67 | ll d = f.fi;
| ^
crocodile.cpp:91:8: warning: unused variable 'd' [-Wunused-variable]
91 | ll d = f.fi;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |