### Serioton_codes's blog

By Serioton_codes, history, 5 weeks ago,

can someone help me out why my code is giving wrong answers for some test cases ? Following is my code-

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll INF = -1e16;
int n, m;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> p;
p.push({0, 1});
vector<int> vis(n + 1, 0), dist(n + 1, 1e9), parent(n + 1, -1);
dist[1] = 0;
while (!p.empty())
{
int u = p.top().second;
int dis = p.top().first;
p.pop();
if (vis[u])
continue;

vis[u] = 1;
{
if (dist[adjnode] > dis - 1)
{
}
}
}

vector<int> ans;
int x = n;
while (parent[x] != -1)
{
ans.push_back(x);
x = parent[x];
}
if (x != 1)
{
cout << "IMPOSSIBLE" << endl;
return 0;
}
cout << ans.size() + 1 << endl;
cout << 1 << " ";

reverse(ans.begin(), ans.end());

for (auto it : ans)
cout << it << " ";
cout << endl;

return 0;
}

• 0

 » 5 weeks ago, # |   0 Dijkstra with negative edge weights does not work. SpoilerYou need to use something something called topological sort.