# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
472350 |
2021-09-13T12:06:34 Z |
morasha3 |
Toll (BOI17_toll) |
C++17 |
|
60 ms |
7004 KB |
#include<bits/stdc++.h>
typedef long long ll;
const ll mod = (ll) 1e9 + 7;
const ll mx = (ll) 1e5 +7;
using namespace std;
vector<vector<pair<ll,ll>>>v(50007);
ll k,n,q,m,ans=0;
ll vis[50007],dis[50007];
void dfs(ll idx,ll cnt)
{
vis[idx]=1;
if(dis[idx]!=-1)
dis[idx]=min(dis[idx],cnt);
else dis[idx]=cnt;
for(int i=0; i<v[idx].size(); i++)
{
if(dis[v[idx][i].first]!=-1)
dis[v[idx][i].first]=min(dis[v[idx][i].first],cnt+v[idx][i].second);
else dis[v[idx][i].first]=cnt+v[idx][i].second;
if(vis[v[idx][i].first]==0)
dfs(v[idx][i].first,cnt+v[idx][i].second);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>k>>n>>m>>q;
memset(vis,0,sizeof vis);
for(int i=0; i<m; i++)
{
ll a,b,c;
cin>>a>>b>>c;
v[a].push_back({b,c});
}
memset(dis,-1,sizeof dis);
dfs(0,0);
for(int i=0; i<q; i++)
{
ll a,b;
ans=INT_MAX;
cin>>a>>b;
if(dis[b]==-1)ans=-1;
else ans=dis[b];
cout<<ans<<endl;
}
}
Compilation message
toll.cpp: In function 'void dfs(ll, ll)':
toll.cpp:15:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(int i=0; i<v[idx].size(); i++)
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
7004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
60 ms |
5564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2252 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2252 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
7004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |