답안 #924461

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
924461 2024-02-09T04:45:00 Z Muhammad_Aneeq Toll (BOI17_toll) C++17
0 / 100
3000 ms 4688 KB
/*
بسم الله الرحمن الرحيم
Author:
                          (:Muhammad Aneeq:)
*/

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int const N=5e4+10;
vector<pair<int,int>>nei[N]={};
int dist[N]={};
bool vis[N]={};
void bfs(int n)
{
    priority_queue<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;
        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});
            }
        }
    }
}
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});
        nei[b].push_back({a,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;
            bfs(i.first);
            cout<<(dist[i.second]==1e9+10?-1:dist[i.second])<<'\n';
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
        solve();
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3005 ms 3904 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 4688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Incorrect 1 ms 1628 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Incorrect 1 ms 1628 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3005 ms 3904 KB Time limit exceeded
2 Halted 0 ms 0 KB -