Submission #871050

# Submission time Handle Problem Language Result Execution time Memory
871050 2023-11-09T18:58:35 Z Cyber_Wolf Autobus (COCI22_autobus) C++17
0 / 70
199 ms 16208 KB
#include <bits/stdc++.h>

using namespace std;

#define lg long long 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const lg N = 100;

lg d[N][N][N], cost[N][N], in_queue[N][N][N];

int main()
{
	fastio;
	lg n, m;
	cin >> n >> m;
	memset(d, 0x3f, sizeof(d));
	memset(cost, 0x3f, sizeof(cost));
	for(int i = 0; i < m; i++)
	{
		lg a, b, t;
		cin >> a >> b >> t;
		cost[a][b] = min(cost[a][b], t);
	}
	priority_queue<array<lg, 3>> pq;
	for(int i = 1; i <= n; i++)	
	{
		pq.push({0, i, 0});
		in_queue[i][i][0] = true;
		d[i][i][0] = 0;
		while(pq.size())
		{
			lg u = pq.top()[1], v = pq.top()[2];
			pq.pop();
			in_queue[i][u][v] = false;
			for(int j = 1; j <= n; j++)
			{
				if(cost[u][j] > 1e6)	continue;
				if(d[i][j][v+1] > d[i][u][v]+cost[u][j])
				{
					d[i][j][v+1] = d[i][u][v]+cost[u][j];
					// if(in_queue[i][j][v+1])	continue;
					in_queue[i][j][v+1] = true;
					pq.push({-d[i][j][v+1], j, v+1});
				}
			}
		}
		for(int j = 1; j <= n; j++)
		{
			for(int z = 1; z <= n; z++)
			{
				d[i][j][z] = min(d[i][j][z], d[i][j][z-1]);
			}
		}
	}
	lg k, q;
	cin >>  k >> q;
	k = min(k, n);
	// for(int i = 1; i <= n; i++)
	// {
		// for(int j = 1; j <= n; j++)
		// {
			// cout << d[i][j][k] << ' ';
		// }
		// cout << '\n';
	// }
	while(q--)
	{
		lg c, e;
		cin >> c >> e;
		if(d[c][e][k] > 1e9)
		{
			cout << "-1\n";
			continue;
		}
		cout << d[c][e][k] << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 92 ms 15996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 199 ms 16208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 92 ms 15996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 92 ms 15996 KB Output isn't correct
2 Halted 0 ms 0 KB -