I am getting wrong answer for the following code but it runs perfectly on spoj toolkit. Plz have a look on my code and suggest any fixes required.
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii>iii;
vector *adj;
int n,m,k;
priority_queue<iii,vector,greater> pq;
void dijkstra()
{
bool flag=false;
vis=vector(n+1,false);
int w,u,c;
pq.push(iii(0,ii(0,1)));
while(!pq.empty())
{
iii temp = pq.top();
pq.pop();
u=temp.second.second;
c=temp.second.first;
w=temp.first;
if(u==n){
flag=true;
break;
}
for(auto i:adj[u])
{
int v = i.first;
int weight = i.second.first;
int cost = i.second.second;
if(c+cost<=k)
{
pq.push(iii(w+weight,ii(c+cost,v)));
}
}
}
if(flag)cout<<w<<endl;
else cout<<"-1"<<endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen(“input.txt”,“r”,stdin);
#endif // ONLINE_JUDGE
int t;
cin>>t;
while(t–){
cin>>k>>n>>m;
adj = new vector [n+1];
for(int i=0;i<m;i++){
int u,v,w,c;
cin>>u>>v>>w>>c;
adj[u].push_back(iii(v,ii(w,c)));
}
dijkstra();
}
}