27112023-01-19 10:29:11kohumarkVillanyautócpp11Time limit exceeded 0/601.08s7868 KiB
#include <iostream>
#include <vector>
#include <climits>
using namespace std;

//vector<vector<pair<int,int>>> put;
int accu=0;
int put[100][100];

void ut(vector<vector<pair<int,int>>> utak, int act, int b, int cost, int& val, vector<bool> visited){
	if(visited[act]==false){
		visited[act]=true;
		if(act==b&&cost<val) val=cost;
		else{
			for(auto uti : utak[act]) ut(utak, uti.first, b, cost+uti.second, val, visited);
		} 
	}
}

void keres(int n, int act, int b, int k, int len, int mx, int& x, vector<bool> visited){
	if(len <= k){
		if(act==b){
			x=min(mx,x);
			//cout << x << ' ' << b << '\n';
		}
		else{
			for(int i=0; i<n; i++) if(visited[i]==false) keres(n, i, b, k, len+1, max(mx,put[act][i]), x, visited);
		}
	}
}

int main(){
	int n, m, k; cin >> n >> m >> k;
	vector<vector<pair<int,int>>> utak; utak.assign(n,vector<pair<int,int>>());
	for(int i=0; i<m; i++){
		int a, b, c; cin >> a >> b >> c; a--; b--;
		utak[a].push_back(make_pair(b,c));
		utak[b].push_back(make_pair(a,c));
	}
	//put.assign(n,vector<pair<int,int>>());
	
	vector<bool> visited; visited.assign(n,false);
	//int put[n][n];
	for(int i=0; i<n; i++) for(int j=0; j<n; j++) put[i][j]=INT_MAX;
	
	for(int i=0; i<n; i++) for(int j=i; j<n; j++){
		ut(utak, i, j, 0, put[i][j], visited);
		put[j][i]=put[i][j];
		//cout << put[i][j] << ' ' << i << ' ' << j << '\n';
	}
	
	for(int i=0; i<n; i++) for(int j=i; j<n; j++){
		int x=INT_MAX;
		keres(n,i,j,k,0,0,x,visited);
		accu = max(accu,x);
	}
	
	cout << accu;
}
SubtaskSumTestVerdictTimeMemory
base0/60
1Accepted0/03ms1688 KiB
2Time limit exceeded0/01.072s2472 KiB
3Time limit exceeded0/11.069s1708 KiB
4Time limit exceeded0/11.052s2300 KiB
5Time limit exceeded0/11.052s2752 KiB
6Time limit exceeded0/21.06s2672 KiB
7Time limit exceeded0/21.07s5016 KiB
8Time limit exceeded0/21.054s7748 KiB
9Time limit exceeded0/11.052s2636 KiB
10Time limit exceeded0/11.065s2684 KiB
11Time limit exceeded0/11.07s2868 KiB
12Time limit exceeded0/21.049s3168 KiB
13Time limit exceeded0/21.049s3228 KiB
14Time limit exceeded0/21.06s3352 KiB
15Time limit exceeded0/31.052s3472 KiB
16Time limit exceeded0/31.074s4088 KiB
17Time limit exceeded0/21.07s3264 KiB
18Time limit exceeded0/21.009s4172 KiB
19Time limit exceeded0/21.037s4076 KiB
20Time limit exceeded0/21.072s4552 KiB
21Time limit exceeded0/21.065s3908 KiB
22Time limit exceeded0/21.08s3664 KiB
23Time limit exceeded0/31.065s3916 KiB
24Time limit exceeded0/31.057s5756 KiB
25Time limit exceeded0/31.07s6144 KiB
26Time limit exceeded0/31.065s7868 KiB
27Time limit exceeded0/31.046s5116 KiB
28Time limit exceeded0/31.057s4348 KiB
29Time limit exceeded0/31.07s4444 KiB
30Time limit exceeded0/31.072s4584 KiB