답안 #690848

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
690848 2023-01-30T13:02:27 Z Warinchai Autobus (COCI22_autobus) C++14
30 / 70
1000 ms 2140 KB
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> >ar[75];
int mn[75][75][75];
int k,q;
void dfs(int x,int dis,int rt,int st){
	//cout<<x<<" "<<dis<<" "<<rt<<endl;
	for(int i=0;i<ar[x].size();i++){
		if(dis+ar[x][i].second<mn[st][ar[x][i].first][rt+1]&&rt<=k){
			mn[st][ar[x][i].first][rt+1]=dis+ar[x][i].second;
			dfs(ar[x][i].first,dis+ar[x][i].second,rt+1,st);
		}
	}
}
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<75;i++){
		for(int j=0;j<75;j++){
			for(int k=0;k<75;k++){
				mn[i][j][k]=INT_MAX;
				if(i==j){
					mn[i][j][k]=0;
				}
			}
		}
	}
	
	for(int i=0;i<m;i++){
		int a,b,c;
		cin>>a>>b>>c;
		ar[a].push_back({b,c});
	}
	cin>>k>>q;
	if(k>n){
		k=n;
	}
	//cout<<endl<<"info:\n";
	for(int i=1;i<=n;i++){
		//cout<<"i: "<<i<<endl;
		dfs(i,0,0,i);
	}
	/*for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int l=1;l<=k;l++){
				cout<<mn[i][j][l]<<" ";
			}
			cout<<endl;
		}
		cout<<"----------------------"<<endl;
	}*/
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			int mnn=INT_MAX;
			for(int l=1;l<=k;l++){
				mnn=min(mnn,mn[i][j][l]);
			}
			mn[i][j][k]=mnn;
		}
	}
	for(int i=0;i<q;i++){
		int c,d;
		cin>>c>>d;
		if(mn[c][d][k]==INT_MAX){
			cout<<"-1\n";
		}else{
			cout<<mn[c][d][k]<<"\n";
		}
	}
}

Compilation message

Main.cpp: In function 'void dfs(int, int, int, int)':
Main.cpp:8:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  for(int i=0;i<ar[x].size();i++){
      |              ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1852 KB Output is correct
2 Correct 2 ms 1980 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 2 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 2008 KB Output is correct
2 Correct 10 ms 2004 KB Output is correct
3 Correct 11 ms 1988 KB Output is correct
4 Correct 13 ms 1988 KB Output is correct
5 Correct 17 ms 1992 KB Output is correct
6 Correct 19 ms 2140 KB Output is correct
7 Correct 23 ms 2136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1852 KB Output is correct
2 Correct 2 ms 1980 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 2 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 215 ms 1996 KB Output is correct
8 Execution timed out 1087 ms 1876 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1852 KB Output is correct
2 Correct 2 ms 1980 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 2 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 12 ms 2008 KB Output is correct
8 Correct 10 ms 2004 KB Output is correct
9 Correct 11 ms 1988 KB Output is correct
10 Correct 13 ms 1988 KB Output is correct
11 Correct 17 ms 1992 KB Output is correct
12 Correct 19 ms 2140 KB Output is correct
13 Correct 23 ms 2136 KB Output is correct
14 Correct 215 ms 1996 KB Output is correct
15 Execution timed out 1087 ms 1876 KB Time limit exceeded
16 Halted 0 ms 0 KB -