| Task: | Shortest Routes I |
| Sender: | Ciphra |
| Submission time: | 2025-10-06 17:14:17 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.00 s | details |
| #3 | WRONG ANSWER | 0.00 s | details |
| #4 | ACCEPTED | 0.00 s | details |
| #5 | ACCEPTED | 0.00 s | details |
| #6 | TIME LIMIT EXCEEDED | -- | details |
| #7 | TIME LIMIT EXCEEDED | -- | details |
| #8 | TIME LIMIT EXCEEDED | -- | details |
| #9 | TIME LIMIT EXCEEDED | -- | details |
| #10 | TIME LIMIT EXCEEDED | -- | details |
| #11 | ACCEPTED | 0.26 s | details |
| #12 | TIME LIMIT EXCEEDED | -- | details |
| #13 | ACCEPTED | 0.00 s | details |
| #14 | TIME LIMIT EXCEEDED | -- | details |
| #15 | TIME LIMIT EXCEEDED | -- | details |
| #16 | ACCEPTED | 0.27 s | details |
| #17 | WRONG ANSWER | 0.26 s | details |
| #18 | ACCEPTED | 0.33 s | details |
Compiler report
input/code.cpp: In constructor 'Dijkstra::Dijkstra(std::vector<std::unordered_set<int> >, std::unordered_map<std::pair<int, int>, int, hashPair>)':
input/code.cpp:33:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::unordered_set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i = 0; i<neighbors.size(); ++i){
| ~^~~~~~~~~~~~~~~~~
input/code.cpp: In member function 'void Dijkstra::find(int)':
input/code.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::unordered_set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 0; i<neighbors.size(); ++i){
| ~^~~~~~~~~~~~~~~~~Code
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
struct hashPair{
size_t operator()(const std::pair<int, int>& p) const{
return std::hash<int>{}(p.first) ^ std::hash<int>{}(p.second);
}
};
// Dijkstra
struct Dijkstra {
std::vector<std::unordered_set<int>> neighbors;
std::unordered_map<std::pair<int, int>, int, hashPair> edgesDist;
std::vector<int> dist;
std::vector<int> prev;
std::vector<int> vertices;
Dijkstra(std::vector<std::unordered_set<int>> ne, std::unordered_map<std::pair<int, int>, int, hashPair> edgesDist):neighbors(ne), edgesDist(edgesDist){
//Vertices
vertices.resize(neighbors.size());
dist.resize(neighbors.size());
prev.resize(neighbors.size());
for (int i = 0; i<neighbors.size(); ++i){
vertices[i] = i;
}
}
void find(int source){
auto cmp = [&](int v1, int v2){
return dist[v1] < dist[v2];
};
for (int i = 0; i<neighbors.size(); ++i){
dist[i] = std::numeric_limits<int>::max();
prev[i] = -1; //null
}
dist[source] = 0;
std::multiset verts(vertices.begin(), vertices.end(), cmp);
while (!verts.empty()){
int u = *verts.cbegin();
verts.erase(verts.begin());
for (int ne : neighbors[u]){
int alt_dist = dist[u] + edgesDist[{u, ne}];
if (alt_dist<dist[ne]){
dist[ne] = alt_dist;
prev[ne] = u;
if (auto it = verts.find(ne); it !=verts.end()){
verts.erase(it);
verts.insert(ne);
};
}
}
}
}
};
int main(){
int n, m;
std::cin >> n >> m;
std::vector<std::unordered_set<int>> neighbors(n);
std::unordered_map<std::pair<int, int>, int, hashPair> edgesDist;
for (int i = 0; i<m; ++i){
int c1, c2, dist;
std::cin >> c1 >> c2 >> dist;
neighbors[c1-1].insert(c2-1);
// neighbors[c2-1].push_back(c1-1);
if (edgesDist.contains({c1-1, c2-1})){
edgesDist[{c1-1, c2-1}] = std::min(dist, edgesDist[{c1-1, c2-1}]);
} else {
edgesDist[{c1-1, c2-1}] = dist;
}
}
Dijkstra dij(neighbors, edgesDist);
dij.find(0);
for (int i = 0; i<n; ++i){
std::cout << dij.dist[i] << " ";
}
std::cout << "\n";
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 10 20 8 5 1 9 10 2 7 9 8 9 8 8 ... |
| correct output |
|---|
| 0 9 11 20 13 14 19 29 27 29 |
| user output |
|---|
| 0 9 11 20 13 14 19 29 27 29 |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 10 20 5 6 4 5 1 7 7 4 4 7 8 1 ... |
| correct output |
|---|
| 0 7 9 17 15 17 21 22 25 30 |
| user output |
|---|
| 0 7 9 17 15 17 21 22 25 30 |
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 10 20 1 4 1 4 2 1 9 10 1 1 2 4 ... |
| correct output |
|---|
| 0 2 11 1 2 7 16 18 12 13 |
| user output |
|---|
| 0 2 -2147483632 1 2 -214748363... |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 10 20 6 3 5 7 5 8 5 1 8 8 9 5 ... |
| correct output |
|---|
| 0 5 9 18 22 10 14 23 27 36 |
| user output |
|---|
| 0 5 9 18 22 10 14 23 27 36 |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 10 20 8 9 3 2 3 8 10 5 3 2 5 3 ... |
| correct output |
|---|
| 0 8 16 18 11 17 24 23 16 26 |
| user output |
|---|
| 0 8 16 18 11 17 24 23 16 26 |
Test 6
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 200000 18000 18001 426710313 73018 73012 558438094 87726 87671 355171790 53170 53171 869493690 ... |
| correct output |
|---|
| 0 479659405 1165315262 1854343... |
| user output |
|---|
| (empty) |
Test 7
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 200000 26504 26450 258578924 49543 49544 28958186 75174 75175 89459846 39175 39228 119699475 ... |
| correct output |
|---|
| 0 655556128 1413395076 1814086... |
| user output |
|---|
| (empty) |
Test 8
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 200000 39477 39413 773046299 69758 69759 558754983 23279 23280 142570619 61416 61479 874921013 ... |
| correct output |
|---|
| 0 269736525 626115013 70199222... |
| user output |
|---|
| (empty) |
Test 9
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 200000 76662 76636 844365635 73339 73342 755006676 89878 89879 396562588 18801 18781 954807004 ... |
| correct output |
|---|
| 0 598585836 1267139909 1803859... |
| user output |
|---|
| (empty) |
Test 10
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 200000 11724 11725 818399968 33244 33197 722525474 65530 65531 483965413 62405 62454 199581867 ... |
| correct output |
|---|
| 0 387990617 441010945 92441292... |
| user output |
|---|
| (empty) |
Test 11
Verdict: ACCEPTED
| input |
|---|
| 100000 200000 1 2 1 1 3 1 1 4 1 1 5 1 ... |
| correct output |
|---|
| 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| user output |
|---|
| 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
Test 12
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 99999 1 2 1000000000 2 3 1000000000 3 4 1000000000 4 5 1000000000 ... |
| correct output |
|---|
| 0 1000000000 2000000000 300000... |
| user output |
|---|
| (empty) |
Test 13
Verdict: ACCEPTED
| input |
|---|
| 1 1 1 1 1 |
| correct output |
|---|
| 0 |
| user output |
|---|
| 0 |
Test 14
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 99999 149997 1 2 1 2 3 1 3 4 1 4 5 1 ... |
| correct output |
|---|
| 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 ... |
| user output |
|---|
| (empty) |
Test 15
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 99997 149994 1 3 3 3 5 3 5 7 3 7 9 3 ... |
| correct output |
|---|
| 0 1 2 3 4 5 6 7 8 9 10 11 12 1... |
| user output |
|---|
| (empty) |
Test 16
Verdict: ACCEPTED
| input |
|---|
| 60003 120000 1 2 30010 1 3 30010 1 4 30010 1 5 30010 ... |
| correct output |
|---|
| 0 30010 30010 30010 30010 3001... |
| user output |
|---|
| 0 30010 30010 30010 30010 3001... |
Test 17
Verdict: WRONG ANSWER
| input |
|---|
| 60003 120000 1 2 30010 1 3 30010 1 4 30010 1 5 30010 ... |
| correct output |
|---|
| 0 30010 30010 30010 30010 3001... |
| user output |
|---|
| 0 30010 30010 30010 30010 3001... |
Test 18
Verdict: ACCEPTED
| input |
|---|
| 100000 149997 1 50000 99997 1 49999 99995 1 49998 99993 1 49997 99991 ... |
| correct output |
|---|
| 0 1 3 5 7 9 11 13 15 17 19 21 ... |
| user output |
|---|
| 0 1 3 5 7 9 11 13 15 17 19 21 ... |
