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>
#define ll long long
#define fr first
#define sc second
using namespace std;
vector <pair <ll,ll> > v[100001];
ll dp[100001],us[100001];
priority_queue <pair <ll,ll> > q;
ll dfs(ll x,ll y)
{
us[x]=-1;
if (x==y) return us[x]=dp[y];
ll ans=0;
for(auto to : v[x])
{
if (us[to.fr]==0)
dfs(to.fr,y);
if (us[to.fr]>0)
ans=max(ans,us[to.fr]);
}
return us[x]=min(ans,dp[x]);
}
bool cmp (pair <ll,ll> a, pair <ll,ll> b)
{
if (a.sc>=b.sc)
return 1;
return 0;
}
int main()
{
ios_base::sync_with_stdio(0);
ll n,m,Q,k,i,j;
cin>>n>>m;
for(i=1;i<=n;i++)
dp[i]=1e9;
for(i=1;i<=m;i++)
{
ll x,y,z;
cin>>x>>y>>z;
v[x].push_back({y,z});
v[y].push_back({x,z});
}
for(i=1;i<=n;i++)
sort(v[i].begin(),v[i].end(),cmp);
cin>>k;
for(i=1;i<=k;i++)
{
ll x,y;
cin>>x;
q.push({0,x});
dp[x]=0;
}
while(!q.empty())
{
ll from=q.top().sc;
ll weight=-q.top().fr;
q.pop();
if (dp[from]<weight)
continue;
for(auto to : v[from])
{
if (dp[to.fr]>dp[from]+to.sc)
{
dp[to.fr]=dp[from]+to.sc;
q.push({-(dp[from]+to.sc),to.fr});
}
}
}
//return 0;
cin>>Q;
for(i=1;i<=Q;i++)
{
ll x,y;
for(ll j=1;j<=n;j++)
us[j]=0;
cin>>x>>y;
cout<<min(x,y)<<endl;
}
return 0;
}
Compilation message (stderr)
plan.cpp: In function 'int main()':
plan.cpp:48:14: warning: unused variable 'y' [-Wunused-variable]
ll x,y;
^
plan.cpp:32:18: warning: unused variable 'j' [-Wunused-variable]
ll n,m,Q,k,i,j;
^
# | 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... |