#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define vi vector<int>
#define ve vector
#define ll long long
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define onbit __builtin_popcount
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e18
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
using namespace std;
using namespace __gnu_pbds;
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MOD = 1e9+7;
const int nax = 1e5+5;
const int MAX_VAL = 1e9;
double PI=3.14159265359;
int arx[8]={1,1,0,-1,-1,-1, 0, 1};
int ary[8]={0,1,1, 1, 0,-1,-1,-1};
typedef complex<int> Point;
#define X real()
#define Y imag()
template<typename T, typename U>
ostream & operator << (ostream &out, const pair<T, U> &c) {
out << c.first << ' ' << c.second;
return out;
}
template<typename T>
ostream & operator << (ostream &out, vector<T> &v) {
const int sz = v.size();
for (int i = 0; i < sz; i++) {
if (i) out << ' ';
out << v[i];
}
return out;
}
template<typename T>
istream & operator >> (istream &in, vector<T> &v) {
for (T &x : v) in >> x;
return in;
}
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
vector<pair<int,int>> adj[nax];
vector<int> dis(nax);
int dp[nax];
vector<bool> tab(nax);
bool vis[nax];
int dfs(int x,int p)
{
if (tab[x]==1) return 0;
if (dp[x]!=-1) return dp[x];
dp[x]=1e9+7;
//cout << x<<" ";
priority_queue<pair<pair<int,int>,int>,vector<pair<pair<int,int>,int>>,greater<>> pq;
for(auto u:adj[x])
{
if (u.fi==p) continue;
pq.push({{dis[u.fi]+u.se,u.se},u.fi});
}
//cout << pq.top().se<<endl;
pq.pop();
while(!pq.empty())
{
int a=pq.top().fi.fi;
int b=pq.top().fi.se;
int c=pq.top().se;
pq.pop();
if (vis[c]) continue;
vis[c]=1;
dp[x]=min(dp[x],dfs(c,x)+b);
}
return dp[x];
}
ll travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
int n = N;
vi bahma(K);
memset(dp,-1,sizeof dp);
for(int i = 0; i < M; i++) {
int x = R[i][0];
int y = R[i][1];
int t = L[i];
bahma[i]=L[i];
tab[L[i]]=1;
adj[x].pb({y, t});
adj[y].pb({x, t});
}
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<>> pq;
for (int i = 0; i < K; ++i)
{
pq.push({bahma[i],0});
dis[bahma[i]]=0;
}
while(!pq.empty())
{
int x=pq.top().fi;
int y=pq.top().se;
pq.pop();
for(auto u:adj[y])
{
int node=u.fi;
int d=u.se;
if (dis[node]<=x+d) continue;
else{
dis[node]=x+d;
pq.push({x+d,node});
}
}
}
return dfs(0,-1);
}
/*int main(){
optimise;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
//setIO("pump");
}*/
Compilation message
crocodile.cpp: In function 'int dfs(int, int)':
crocodile.cpp:81:13: warning: unused variable 'a' [-Wunused-variable]
81 | int a=pq.top().fi.fi;
| ^
crocodile.cpp: In function 'long long int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:92:9: warning: unused variable 'n' [-Wunused-variable]
92 | int n = N;
| ^
crocodile.cpp: In function 'void setIO(std::string)':
crocodile.cpp:57:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
crocodile.cpp:58:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
6092 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
6092 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
6092 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |