답안 #924480

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
924480 2024-02-09T05:16:25 Z Faisal_Saqib Toll (BOI17_toll) C++17
0 / 100
3000 ms 3652 KB
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int N=5e4;
vector<pair<int,int>> ma[N];
int dist[N];
int main()
{
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
	int k,n,m,q;
	cin>>k>>n>>m>>q;
	for(int j=0;j<m;j++)
	{
		int a,b,t;
		cin>>a>>b>>t;
		ma[a].push_back({b,t});
	}
  	for(int i=0;i<n;i++)
      dist[i]=1e9;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
	for(int lp=0;lp<q;lp++)
	{
		int x,y;
		cin>>x>>y;
      if(dist[x]==0)
      {
        if(dist[y]==1e9)
          cout<<-1<<'\n';
        else
          cout<<dist[y]<<'\n';
        continue;
		}
		for(int i=0;i<n;i++)
			dist[i]=1e9;
		dist[x]=0;
		int ans=-1;
		pq.push({dist[x],x});
		while(pq.size())
		{
			auto it=pq.top();
			pq.pop();
			if(dist[it.second]==it.first)
			{
              if(it.second==y)
              {
                ans=it.first;
              }
				for(auto [v,w]:ma[it.second])
				{
					if(dist[v]>(it.first+w) and v<=y)
					{
						dist[v]=it.first+w;
						pq.push({dist[v],v});
					}
				}
			}
		}
		cout<<ans<<'\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3059 ms 3652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Incorrect 1 ms 1628 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Incorrect 1 ms 1628 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3059 ms 3652 KB Time limit exceeded
2 Halted 0 ms 0 KB -