#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
vector<pair<int,int> > G[100010];
vector<int> exits;
int dijkstra()
{
int vis[n];
memset(vis,0,sizeof(vis));
priority_queue<pair<int,int> > pq;
for(int i=0;i<exits.size();i++)
{
int exit = exits[i];
pq.push(make_pair(0,exit));
vis[exit] = 1;
}
while(!pq.empty())
{
pair<int,int> state = pq.top(); pq.pop();
int path = -state.first;
int city = state.second;
//cout<<"at city "<<city<<" with path "<<path<<endl;
if(vis[city] == 0){
vis[city] = 1;
continue;
}
if(vis[city] == 2)
continue;
if(city == 0)
return path;
vis[city] = 2;
vector<pair<int,int> > can_go = G[city];
for(int i=0;i<can_go.size();i++)
{
int next = can_go[i].first;
int len = can_go[i].second;
len += path;
pq.push(make_pair(-len,next));
}
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
n = N;
m = M;
k = K;
for(int i = 0; i < m; i++){
int a, b, c;
a = R[i][0], b = R[i][1], c = L[i];
G[a].push_back(make_pair(b,c));
G[b].push_back(make_pair(a,c));
}
for(int i = 0; i < k; i++){
int exit = P[i];
exits.push_back(exit);
}
return dijkstra();
}
/*int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m>>k;
for(int i =0;i<m;i++)
{
int a, b, c;
cin>>a>>b>>c;
G[a].push_back(make_pair(b,c));
G[b].push_back(make_pair(a,c));
}
for(int i =0;i<k;i++)
{
int exit;
cin>>exit;
exits.push_back(exit);
}
cout<<dijkstra()<<endl;
return 0;
} */
Compilation message
crocodile.cpp: In function 'int dijkstra()':
crocodile.cpp:12:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<exits.size();i++)
~^~~~~~~~~~~~~
crocodile.cpp:36:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<can_go.size();i++)
~^~~~~~~~~~~~~~
crocodile.cpp:45:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
7 ms |
2688 KB |
Output is correct |
4 |
Correct |
7 ms |
2816 KB |
Output is correct |
5 |
Correct |
7 ms |
2688 KB |
Output is correct |
6 |
Correct |
7 ms |
2732 KB |
Output is correct |
7 |
Correct |
7 ms |
2816 KB |
Output is correct |
8 |
Correct |
7 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
7 ms |
2688 KB |
Output is correct |
4 |
Correct |
7 ms |
2816 KB |
Output is correct |
5 |
Correct |
7 ms |
2688 KB |
Output is correct |
6 |
Correct |
7 ms |
2732 KB |
Output is correct |
7 |
Correct |
7 ms |
2816 KB |
Output is correct |
8 |
Correct |
7 ms |
2816 KB |
Output is correct |
9 |
Correct |
8 ms |
3072 KB |
Output is correct |
10 |
Correct |
8 ms |
2688 KB |
Output is correct |
11 |
Correct |
8 ms |
2816 KB |
Output is correct |
12 |
Correct |
12 ms |
3488 KB |
Output is correct |
13 |
Correct |
11 ms |
3584 KB |
Output is correct |
14 |
Correct |
8 ms |
2688 KB |
Output is correct |
15 |
Correct |
7 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
7 ms |
2688 KB |
Output is correct |
4 |
Correct |
7 ms |
2816 KB |
Output is correct |
5 |
Correct |
7 ms |
2688 KB |
Output is correct |
6 |
Correct |
7 ms |
2732 KB |
Output is correct |
7 |
Correct |
7 ms |
2816 KB |
Output is correct |
8 |
Correct |
7 ms |
2816 KB |
Output is correct |
9 |
Correct |
8 ms |
3072 KB |
Output is correct |
10 |
Correct |
8 ms |
2688 KB |
Output is correct |
11 |
Correct |
8 ms |
2816 KB |
Output is correct |
12 |
Correct |
12 ms |
3488 KB |
Output is correct |
13 |
Correct |
11 ms |
3584 KB |
Output is correct |
14 |
Correct |
8 ms |
2688 KB |
Output is correct |
15 |
Correct |
7 ms |
2816 KB |
Output is correct |
16 |
Correct |
732 ms |
72352 KB |
Output is correct |
17 |
Correct |
123 ms |
13304 KB |
Output is correct |
18 |
Correct |
135 ms |
14840 KB |
Output is correct |
19 |
Correct |
754 ms |
66912 KB |
Output is correct |
20 |
Correct |
436 ms |
66104 KB |
Output is correct |
21 |
Correct |
64 ms |
7544 KB |
Output is correct |
22 |
Correct |
682 ms |
46460 KB |
Output is correct |