#include "crocodile.h"
#include <stdio.h>
#include <stdlib.h>
#include<bits/stdc++.h>
using namespace std;
/*
#define MAX_N 50000
#define MAX_M 10000000
static int N, M;
static int R[MAX_M][2];
static int L[MAX_M];
static int K;
static int P[MAX_N];
static int solution;
inline
void my_assert(int e) {if (!e) abort();}
void read_input()
{
int i;
my_assert(3==scanf("%d %d %d",&N,&M,&K));
for(i=0; i<M; i++)
my_assert(3==scanf("%d %d %d",&R[i][0],&R[i][1],&L[i]));
for(i=0; i<K; i++)
my_assert(1==scanf("%d",&P[i]));
//my_assert(1==scanf("%d",&solution));
}
*/
vector<int> grafo[100005],peso[100005];
int sol[100005][2],n,m,tmp;
priority_queue<pair<int,int> > pq;
/*
5 4 3
0 1 2
0 2 3
3 2 1
2 4 4
1
3
4
*/
void dfs(int nodo){
for(int i=0;i<grafo[nodo].size();i++){
if(sol[grafo[nodo][i]][0]==-1 || sol[grafo[nodo][i]][0]>(sol[nodo][1]+peso[nodo][i])){
sol[grafo[nodo][i]][1]=sol[grafo[nodo][i]][0];
sol[grafo[nodo][i]][0]=sol[nodo][1]+peso[nodo][i];
if(sol[grafo[nodo][i]][1]!=-1)
pq.push({-sol[grafo[nodo][i]][1],grafo[nodo][i]});
}
else{
if(sol[grafo[nodo][i]][1]==-1 || sol[grafo[nodo][i]][1]>(sol[nodo][1]+peso[nodo][i])){
sol[grafo[nodo][i]][1]=sol[nodo][1]+peso[nodo][i];
pq.push({-sol[grafo[nodo][i]][1],grafo[nodo][i]});
}
}
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
for(int i=0;i<M;i++){
grafo[R[i][0]].push_back(R[i][1]);
grafo[R[i][1]].push_back(R[i][0]);
peso[R[i][0]].push_back(L[i]);
peso[R[i][1]].push_back(L[i]);
}
for(int i=0;i<N;i++)sol[i][0]=sol[i][1]=-1;
for(int i=0;i<K;i++){
sol[P[i]][0]=sol[P[i]][1]=0;
pq.push({0,P[i]});
}
while(pq.size()>0){
tmp=pq.top().second;
pq.pop();
dfs(tmp);
}
return sol[0][1];
}
/*
int main()
{
int ans;
read_input();
ans = travel_plan(N,M,R,L,K,P);
cout<<ans<<endl;
if(ans==solution)
printf("Correct.\n");
else
printf("Incorrect. Returned %d, Expected %d.\n",ans,solution);
return 0;
}
*/
Compilation message
crocodile.cpp: In function 'void dfs(int)':
crocodile.cpp:49:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<grafo[nodo].size();i++){
~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
4984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
4984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
4984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |