답안 #924473

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
924473 2024-02-09T05:10:33 Z Muhammad_Aneeq Toll (BOI17_toll) C++17
컴파일 오류
0 ms 0 KB
/*
بسم الله الرحمن الرحيم
Author:
                          (:Muhammad Aneeq:)
*/

#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std;
map<pair<int,int>,int>d;
int const N=5e4+10;
vector<pair<int,int>>nei[N]={};
int dist[N]={};
bool vis[N]={};
int bfs(int n,int tar)
{
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;
    pq.push({0,n});
    dist[n]=0;
    while (pq.size())
    {
        int z=pq.top().second;
        pq.pop();
        if (vis[z])
            continue;
        if (z==tar)
            return dis[z];
        vis[z]=1;
        for (auto [j,w]:nei[z])
        {
            if (dist[j]>dist[z]+w)
            {
                dist[j]=dist[z]+w;
                pq.push({dist[j],j});
            }
        }
    }
    return -1;
}
inline void solve()
{
    int n,m,k,o;
    cin>>k>>n>>m>>o;
    while (m--)
    {
        int a,b,t;
        cin>>a>>b>>t;
        nei[a].push_back({b,t});
    }
    vector<pair<int,int>>ord;
    bool w=1;
    while (o--)
    {
        int x,y;
        cin>>x>>y;
        w=(w&&(x==0));
        ord.push_back({x,y});
    }
    if (w)
    {   
        for (int i=0;i<n;i++)
            dist[i]=1e9+10,vis[i]=0;
        bfs(0);
        for (auto i:ord)
            cout<<(dist[i.second]==1e9+10?-1:dist[i.second])<<'\n';
    }
    else
    {
        for (auto i:ord)
        {
            for (int j=0;j<n;j++)
                dist[j]=1e9+10,vis[j]=0;
            cout<<bfs(i.first,i.second)<<'\n';
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
        solve();
}

Compilation message

toll.cpp: In function 'int bfs(int, int)':
toll.cpp:29:20: error: 'dis' was not declared in this scope; did you mean 'vis'?
   29 |             return dis[z];
      |                    ^~~
      |                    vis
toll.cpp: In function 'void solve()':
toll.cpp:65:14: error: too few arguments to function 'int bfs(int, int)'
   65 |         bfs(0);
      |              ^
toll.cpp:17:5: note: declared here
   17 | int bfs(int n,int tar)
      |     ^~~