#include <bits/stdc++.h>
using namespace std;
#define lln long long
#define INF 0x3f3f3f3f
using pii = pair<int, int>;
struct edge {
int v;
int weight;
};
int main() {
int n, e; cin >> n >> e;
vector< vector<edge> > adj(n);
for (int i=0;i<e;i++) {
int u, v, w;
cin >> u >> v >> w;
adj[u].push_back({v,w}); //insert the edge essentially
adj[v].push_back({u,w}); //if undirected graph only
}
int source; cin >> source;
vector<int> d(n, INF); // or use numeric_limits<int>::max()
vector<bool> done(n);
priority_queue<pii, vector<pii>, greater<pii> > pq;
pq.push({0, source});
d[source] = 0;
while(!pq.empty()) {
pii k = pq.top(); pq.pop();
int u = k.second;
if(!done[u]) {
for (edge& e : adj[u]) {
if (d[e.v] > d[u] + e.weight) {
d[e.v] = d[u] + e.weight;
pq.push({d[e.v], e.v});
}
}
done[u] = true;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |