Submission #556654

# Submission time Handle Problem Language Result Execution time Memory
556654 2022-05-03T13:22:54 Z elesis Autobus (COCI22_autobus) C++14
70 / 70
425 ms 6912 KB
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int up=1e6+7;
const int mod=1e9+7;
const int inf=1e9;
int binpow(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}
int inv(int x)
{
	int res=binpow(x,mod-2);
	return res;
}
const int N=77;
vector <vector <int>> adj(N,vector <int> (N,inf));
void solve()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		adj[i][i]=0;
	}
	for(int i=0;i<m;i++)
	{
		int u,v,e;
		cin>>u>>v>>e;
		adj[u][v]=min(adj[u][v],e);
	}
	//cout << adj[1][3] << "\n";
	int k,q;
	cin>>k>>q;
	k=min(k,n);
	k--;
	auto ans=adj;
	//cout << ans[1][4] << "\n";
	while(k--)
	{
		auto temp=ans;
		for(int x=1;x<=n;x++)
		{
			for(int y=1;y<=n;y++)
			{
				for(int z=1;z<=n;z++)
				{
					temp[x][y]=min(temp[x][y],ans[x][z]+adj[z][y]);
					//cout << temp[x][y] << " " << x << " " << y << "\n
				}
			}
		}
		ans=temp;
		//cout << temp[1][4] << "\n";
	}
	//cout << ans[1][4] << "\n";
	//cout << ans[1][4] << "\n";
	while(q--)
	{
		int u,v;
		cin>>u>>v;
		if(ans[u][v]>=inf)
		{
			cout << -1 << "\n";
		}
		else
		{
			cout << ans[u][v] << "\n";
		}
	}
}
signed main(){
	//fast
	clock_t start, end;
	start = clock();
	solve();
	end = clock();
	double time_taken=double(end-start)/double(CLOCKS_PER_SEC);
	//cout << "time taken" << " " << time_taken << "\n";
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:93:9: warning: unused variable 'time_taken' [-Wunused-variable]
   93 |  double time_taken=double(end-start)/double(CLOCKS_PER_SEC);
      |         ^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 360 KB Output is correct
2 Correct 12 ms 488 KB Output is correct
3 Correct 10 ms 488 KB Output is correct
4 Correct 11 ms 496 KB Output is correct
5 Correct 13 ms 468 KB Output is correct
6 Correct 13 ms 424 KB Output is correct
7 Correct 14 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 20 ms 488 KB Output is correct
8 Correct 39 ms 472 KB Output is correct
9 Correct 11 ms 468 KB Output is correct
10 Correct 26 ms 476 KB Output is correct
11 Correct 15 ms 468 KB Output is correct
12 Correct 30 ms 468 KB Output is correct
13 Correct 391 ms 6456 KB Output is correct
14 Correct 306 ms 6456 KB Output is correct
15 Correct 340 ms 6476 KB Output is correct
16 Correct 313 ms 6468 KB Output is correct
17 Correct 309 ms 6604 KB Output is correct
18 Correct 374 ms 6604 KB Output is correct
19 Correct 331 ms 6596 KB Output is correct
20 Correct 330 ms 6580 KB Output is correct
21 Correct 378 ms 6592 KB Output is correct
22 Correct 317 ms 6584 KB Output is correct
23 Correct 367 ms 6588 KB Output is correct
24 Correct 321 ms 6604 KB Output is correct
25 Correct 320 ms 6780 KB Output is correct
26 Correct 326 ms 6712 KB Output is correct
27 Correct 324 ms 6912 KB Output is correct
28 Correct 349 ms 6712 KB Output is correct
29 Correct 311 ms 6428 KB Output is correct
30 Correct 375 ms 6452 KB Output is correct
31 Correct 313 ms 6460 KB Output is correct
32 Correct 360 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 9 ms 360 KB Output is correct
8 Correct 12 ms 488 KB Output is correct
9 Correct 10 ms 488 KB Output is correct
10 Correct 11 ms 496 KB Output is correct
11 Correct 13 ms 468 KB Output is correct
12 Correct 13 ms 424 KB Output is correct
13 Correct 14 ms 468 KB Output is correct
14 Correct 20 ms 488 KB Output is correct
15 Correct 39 ms 472 KB Output is correct
16 Correct 11 ms 468 KB Output is correct
17 Correct 26 ms 476 KB Output is correct
18 Correct 15 ms 468 KB Output is correct
19 Correct 30 ms 468 KB Output is correct
20 Correct 391 ms 6456 KB Output is correct
21 Correct 306 ms 6456 KB Output is correct
22 Correct 340 ms 6476 KB Output is correct
23 Correct 313 ms 6468 KB Output is correct
24 Correct 309 ms 6604 KB Output is correct
25 Correct 374 ms 6604 KB Output is correct
26 Correct 331 ms 6596 KB Output is correct
27 Correct 330 ms 6580 KB Output is correct
28 Correct 378 ms 6592 KB Output is correct
29 Correct 317 ms 6584 KB Output is correct
30 Correct 367 ms 6588 KB Output is correct
31 Correct 321 ms 6604 KB Output is correct
32 Correct 320 ms 6780 KB Output is correct
33 Correct 326 ms 6712 KB Output is correct
34 Correct 324 ms 6912 KB Output is correct
35 Correct 349 ms 6712 KB Output is correct
36 Correct 311 ms 6428 KB Output is correct
37 Correct 375 ms 6452 KB Output is correct
38 Correct 313 ms 6460 KB Output is correct
39 Correct 360 ms 6520 KB Output is correct
40 Correct 16 ms 468 KB Output is correct
41 Correct 41 ms 588 KB Output is correct
42 Correct 12 ms 488 KB Output is correct
43 Correct 45 ms 480 KB Output is correct
44 Correct 16 ms 492 KB Output is correct
45 Correct 59 ms 508 KB Output is correct
46 Correct 312 ms 6464 KB Output is correct
47 Correct 314 ms 6496 KB Output is correct
48 Correct 313 ms 6488 KB Output is correct
49 Correct 351 ms 6472 KB Output is correct
50 Correct 318 ms 6656 KB Output is correct
51 Correct 347 ms 6584 KB Output is correct
52 Correct 309 ms 6584 KB Output is correct
53 Correct 372 ms 6580 KB Output is correct
54 Correct 315 ms 6584 KB Output is correct
55 Correct 344 ms 6584 KB Output is correct
56 Correct 333 ms 6716 KB Output is correct
57 Correct 425 ms 6584 KB Output is correct
58 Correct 325 ms 6708 KB Output is correct
59 Correct 359 ms 6716 KB Output is correct
60 Correct 342 ms 6712 KB Output is correct
61 Correct 405 ms 6716 KB Output is correct
62 Correct 310 ms 6452 KB Output is correct
63 Correct 351 ms 6452 KB Output is correct
64 Correct 329 ms 6456 KB Output is correct
65 Correct 370 ms 6452 KB Output is correct