52002023-04-21 23:20:00SleepyOverlordVillanyautócpp17Time limit exceeded 5/601.098s127096 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

struct Path
{
	int node, remaining, charges;
};

int n, m, k;
vector <VPII> g;
LL capacity;
VVI best;

bool bellmanFord(int source)
{
	best.CL, best.RS(n + 1, VI(k + 1, -1));
	queue <Path> fifo;
	Path aux = {source, capacity, 0};
	best[source][0] = capacity;
	fifo.push(aux);
	USI reached;
	while (!fifo.empty())
	{
		Path head = fifo.front();
		reached.INS(head.node);
		fifo.pop();
		for (auto [next, cost] : g[head.node])
		{
			if (cost > capacity) continue;
			int rem, chr;
			if (head.remaining >= cost)
			{
				rem = head.remaining - cost;
				chr = head.charges;
			}
			else
			{
				rem = capacity - cost;
				chr = head.charges + 1;
			}
			if (chr > k) continue;
			if (best[next][chr] == -1 || best[next][chr] < rem)
			{
				best[next][chr] = rem;
				aux = {next, rem, chr};
				fifo.push(aux);
			}
		}
	}
	return reached.SZ == n;
}

bool check()
{
	FOR(i, 1, n)
		if (!bellmanFord(i)) return false;
	return true;
}

int main()
{
	cin >> n >> m >> k;
	g.RS(n + 1);
	FOR(i, 1, m)
	{
		int u, v, c;
		cin >> u >> v >> c;
		g[u].PB({v, c});
		g[v].PB({u, c});
	}

	LL sol = 0;
	FORD(i, 36, 0)
	{
		capacity = sol + (1LL << i);
		if (!check()) sol += (1LL << i);
	}

	cout << sol + 1;

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base5/60
1Accepted0/03ms1808 KiB
2Time limit exceeded0/01.098s1460 KiB
3Wrong answer0/13ms2392 KiB
4Wrong answer0/179ms2684 KiB
5Wrong answer0/1100ms2680 KiB
6Wrong answer0/2115ms2968 KiB
7Wrong answer0/2363ms3176 KiB
8Wrong answer0/2601ms3488 KiB
9Wrong answer0/117ms3412 KiB
10Wrong answer0/114ms3472 KiB
11Wrong answer0/114ms3712 KiB
12Wrong answer0/259ms3948 KiB
13Wrong answer0/254ms3924 KiB
14Wrong answer0/252ms3920 KiB
15Wrong answer0/352ms3924 KiB
16Runtime error0/3109ms127096 KiB
17Wrong answer0/224ms3908 KiB
18Wrong answer0/2180ms4284 KiB
19Wrong answer0/2375ms4272 KiB
20Wrong answer0/2216ms4520 KiB
21Accepted2/2361ms4296 KiB
22Wrong answer0/220ms4436 KiB
23Wrong answer0/3133ms4536 KiB
24Time limit exceeded0/31.065s3856 KiB
25Time limit exceeded0/31.067s3892 KiB
26Time limit exceeded0/31.062s4060 KiB
27Time limit exceeded0/31.087s4900 KiB
28Wrong answer0/3164ms4964 KiB
29Wrong answer0/3181ms5060 KiB
30Accepted3/3409ms4980 KiB