This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
vector<vector<pair<int,int> > > g;
int n,m;
void dijsktra()
{
vector<int> dist(n,1e9);
priority_queue<pair<int,int> , vector<pair<int,int> > , greater<pair<int,int> > > q;
q.push({0,0});
dist[0] = 0;
while(!q.empty())
{
int d = q.top().first;
int u = q.top().second;
q.pop();
for(auto it:g[u])
{
if(dist[it.second]> d + it.first)
{
dist[it.second] = d + it.first;
q.push({dist[it.second],it.second});
}
}
}
cout<<dist[1]<<endl;
}
int main()
{
cin>>m>>n;
vector<int> b(n),p(n);
for(int i=0;i<n;i++)
{
cin>>b[i]>>p[i];
}
g.resize(n);
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==j) continue;
if(b[i]%p[i]==b[j]%p[i]) g[i].push_back({abs(b[j]-b[i])/p[i],j});
}
}
dijsktra();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |