52032023-04-21 23:42:32SleepyOverlordVillanyautócpp17Elfogadva 60/60254ms4848 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;
	LL remaining;
	int charges;
};

int n, m, k;
vector <VPII> g;
LL capacity;
vector <VLL> best;
VI least;

bool bellmanFord(int source)
{
	best.CL, best.RS(n + 1, VLL(k + 1, -1));
	least.CL, least.RS(n + 1, n);
	queue <Path> fifo;
	Path aux = {source, capacity, 1};
	best[source][1] = capacity;
	least[source] = 1;
	fifo.push(aux);
	USI reached;
	while (!fifo.empty())
	{
		Path head = fifo.front();
		reached.INS(head.node);
		if (reached.SZ == n) return true;
		fifo.pop();
		for (auto [next, cost] : g[head.node])
		{
			if (cost > capacity) continue;
			LL rem;
			int 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 (chr > least[next]) continue;
			if (best[next][chr] == -1 || best[next][chr] < rem)
			{
				best[next][chr] = rem;
				least[next] = min(least[next], chr);
				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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base60/60
1Elfogadva0/03ms1808 KiB
2Elfogadva0/0254ms2256 KiB
3Elfogadva1/120ms2288 KiB
4Elfogadva1/128ms2592 KiB
5Elfogadva1/129ms2556 KiB
6Elfogadva2/292ms2736 KiB
7Elfogadva2/2115ms2984 KiB
8Elfogadva2/2159ms3400 KiB
9Elfogadva1/118ms3256 KiB
10Elfogadva1/116ms3392 KiB
11Elfogadva1/116ms3476 KiB
12Elfogadva2/268ms3728 KiB
13Elfogadva2/259ms3936 KiB
14Elfogadva2/254ms4048 KiB
15Elfogadva3/359ms4120 KiB
16Elfogadva3/393ms4388 KiB
17Elfogadva2/216ms4352 KiB
18Elfogadva2/226ms4432 KiB
19Elfogadva2/227ms4424 KiB
20Elfogadva2/230ms4436 KiB
21Elfogadva2/235ms4420 KiB
22Elfogadva2/213ms4404 KiB
23Elfogadva3/367ms4328 KiB
24Elfogadva3/3111ms4452 KiB
25Elfogadva3/3112ms4724 KiB
26Elfogadva3/3143ms4848 KiB
27Elfogadva3/3187ms4768 KiB
28Elfogadva3/375ms4604 KiB
29Elfogadva3/364ms4536 KiB
30Elfogadva3/363ms4556 KiB