52022023-04-21 23:38:33SleepyOverlordVillanyautócpp17Hibás válasz 41/60335ms5012 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;
                        if (reached.CNT(next)) 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
base41/60
1Elfogadva0/03ms1832 KiB
2Elfogadva0/0335ms2184 KiB
3Elfogadva1/130ms2228 KiB
4Hibás válasz0/145ms2248 KiB
5Hibás válasz0/161ms2384 KiB
6Hibás válasz0/2120ms2564 KiB
7Elfogadva2/2195ms2948 KiB
8Elfogadva2/2303ms3192 KiB
9Elfogadva1/128ms3176 KiB
10Elfogadva1/118ms3340 KiB
11Elfogadva1/117ms3428 KiB
12Elfogadva2/2108ms3564 KiB
13Elfogadva2/270ms3772 KiB
14Elfogadva2/263ms3980 KiB
15Elfogadva3/375ms4204 KiB
16Elfogadva3/3287ms4584 KiB
17Hibás válasz0/217ms4612 KiB
18Hibás válasz0/245ms4712 KiB
19Elfogadva2/248ms4720 KiB
20Elfogadva2/256ms4728 KiB
21Elfogadva2/252ms4704 KiB
22Hibás válasz0/217ms4780 KiB
23Elfogadva3/375ms4700 KiB
24Hibás válasz0/3192ms4888 KiB
25Elfogadva3/3196ms5012 KiB
26Elfogadva3/3279ms4956 KiB
27Elfogadva3/3203ms4912 KiB
28Hibás válasz0/389ms4956 KiB
29Hibás válasz0/379ms4876 KiB
30Elfogadva3/371ms4880 KiB