52012023-04-21 23:29:02SleepyOverlordVillanyautócpp17Időlimit túllépés 60/601.1s4972 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;

bool bellmanFord(int source)
{
	best.CL, best.RS(n + 1, VLL(k + 1, -1));
	queue <Path> fifo;
	Path aux = {source, capacity, 1};
	best[source][1] = capacity;
	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 (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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base60/60
1Elfogadva0/03ms1812 KiB
2Időlimit túllépés0/01.1s1404 KiB
3Elfogadva1/119ms2312 KiB
4Elfogadva1/126ms2636 KiB
5Elfogadva1/126ms2968 KiB
6Elfogadva2/286ms2916 KiB
7Elfogadva2/2100ms3104 KiB
8Elfogadva2/2133ms3384 KiB
9Elfogadva1/117ms3296 KiB
10Elfogadva1/116ms3304 KiB
11Elfogadva1/116ms3332 KiB
12Elfogadva2/264ms3552 KiB
13Elfogadva2/257ms3764 KiB
14Elfogadva2/254ms3868 KiB
15Elfogadva3/357ms3992 KiB
16Elfogadva3/376ms4360 KiB
17Elfogadva2/221ms4396 KiB
18Elfogadva2/235ms4460 KiB
19Elfogadva2/254ms4424 KiB
20Elfogadva2/239ms4580 KiB
21Elfogadva2/2103ms4628 KiB
22Elfogadva2/214ms4524 KiB
23Elfogadva3/3143ms4516 KiB
24Elfogadva3/3200ms4648 KiB
25Elfogadva3/3287ms4824 KiB
26Elfogadva3/3321ms4884 KiB
27Elfogadva3/3758ms4848 KiB
28Elfogadva3/3125ms4768 KiB
29Elfogadva3/3116ms4916 KiB
30Elfogadva3/3150ms4972 KiB