답안 #527794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527794 2022-02-18T09:53:15 Z 1ne Autobus (COCI22_autobus) C++14
0 / 70
2 ms 588 KB
#include<bits/stdc++.h>
using namespace std;
struct points{
	int node,dist,kk;
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;cin>>n>>m;
vector<vector<pair<int64_t,int64_t>>>adj(n);
vector<vector<int64_t>>dist(n,vector<int64_t>(n,1e15));
//vector<vector<vector<pair<int64_t,int64_t>>>>arr(n,vector<vector<pair<int64_t,int64_t>>>(n));
for (int i = 0;i<m;++i){
	int64_t x,y,z;cin>>x>>y>>z;
	--x;
	--y;
	dist[x][y] = min(dist[x][y],z);
}
for (int i = 0;i<n;++i){
	for (int j =0;j<n;++j){
		if (i!=j){
			if (dist[i][j]!=1e15){
				adj[i].push_back({j,dist[i][j]});
			}
		}
	}
}
int k,q;cin>>k>>q;
k = min(k,n*n);
vector<vector<vector<int64_t>>>distt(n,vector<vector<int64_t>>(n,vector<int64_t>(k+1,1e15)));
function<void(int)> bfs = [&](int u){
	queue<points>q;
	q.push({u,0,0});
	while(!q.empty()){
		auto v = q.front();
		q.pop();
		for (auto x:adj[v.node]){
			if (v.kk+1<=k&&distt[v.node][x.first][v.kk+1]>x.second + v.dist){
				distt[v.node][x.first][v.kk+1] = x.second + v.dist;
				q.push({v.node,x.second + v.dist,v.kk + 1});
			}
		}
	}
};
for (int i = 0;i<n;++i){
	bfs(i);
}
for (int i = 0;i<q;++i){
	int x,y;cin>>x>>y;
	--x;
	--y;
	if (x==y){
		cout<<0<<'\n';
		continue;
	}
	int64_t ans = 1e15;
	for (int i = 1;i<=k;++i){
		ans = min(distt[x][y][i],ans);
	}
	if (ans==1e15){
		cout<<"-1"<<'\n';
	}
	else cout<<ans<<'\n';
}
return 0;}

Compilation message

Main.cpp: In lambda function:
Main.cpp:40:29: warning: narrowing conversion of '(x.std::pair<long int, long int>::second + ((long int)v.points::dist))' from 'long int' to 'int' [-Wnarrowing]
   40 |     q.push({v.node,x.second + v.dist,v.kk + 1});
      |                    ~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Incorrect 2 ms 588 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -