Submission #498922

# Submission time Handle Problem Language Result Execution time Memory
498922 2021-12-26T17:22:35 Z aurims Cheap flights (LMIO18_pigus_skrydziai) C++14
37 / 100
551 ms 262148 KB
#include <bits/stdc++.h>
#define debug cout << "alio\n"
#define pb push_back
#define ll long long
using namespace std;

struct miestas
{
	vector<int> kaimynai;
	vector<ll> pelnas;

};
vector<miestas> miestai;

int main()
{
	int N, M;
	cin >> N >> M;
	miestai.resize(N);
	for(int i = 0; i < N; i++)
	{
		miestai[i].pelnas.resize(N);
		for(int j = 0; j < N; j++)
		{
			miestai[i].pelnas[j] = -1;
		}
	}
	for(int i = 0; i < M; i++)
	{
		int a, b;
		ll p;
		cin >> a >> b >> p;
		miestai[a-1].kaimynai.pb(b-1);
		miestai[b-1].kaimynai.pb(a-1);
		miestai[a-1].pelnas[b-1] = p;
		miestai[b-1].pelnas[a-1] = p;
	}
	ll mx = -1;
	for(int i = 0; i < N; i++)
	{
		if(miestai[i].kaimynai.empty())
			continue;
		ll sum_tr = 0;
		ll sum_zv = 0;
		// perrenkam zvaigzdes
		for(int sidx : miestai[i].kaimynai)
		{
			sum_zv += miestai[i].pelnas[sidx];
		}
		// perrenkam trikampius
		//cout << i << "-tojo miesto kaimynai:\n";
		for(int j = 0; j < miestai[i].kaimynai.size()-1; j++) // gali pasirodyt, kad kils gresme jeigu yra tik du miestai, kuriuos jungia 1 briauna, bet td jie po zvaigzdute palenda ir juos vstk isrenka, net nereikia sito ciklo
		{
			int kaim1 = miestai[i].kaimynai[j];
			int kaim2 = miestai[i].kaimynai[j+1];
			/*
			cout << kaim1 << ' ' << miestai[i].pelnas[kaim1] << '\n';
			cout << kaim2 << ' ' << miestai[i].pelnas[kaim2] << '\n';
			cout << "Tarpusavy " << miestai[kaim1].pelnas[kaim2] << '\n';
			*/
			if(miestai[kaim1].pelnas[kaim2] != -1) // jeigu i-tojo miesto kaimynai j ir j+1 irgi turi kelia, tai susidaro trikampis
				sum_tr = miestai[i].pelnas[kaim1]+miestai[i].pelnas[kaim2]+miestai[kaim1].pelnas[kaim2];
			//cout << '\n';
		}
		if(sum_zv > mx) mx = sum_zv;
		if(sum_tr > mx) mx = sum_tr;
	}
	cout << mx << '\n';
}

Compilation message

pigus_skrydziai.cpp: In function 'int main()':
pigus_skrydziai.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for(int j = 0; j < miestai[i].kaimynai.size()-1; j++) // gali pasirodyt, kad kils gresme jeigu yra tik du miestai, kuriuos jungia 1 briauna, bet td jie po zvaigzdute palenda ir juos vstk isrenka, net nereikia sito ciklo
      |                  ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 268 KB Output is correct
5 Correct 0 ms 292 KB Output is correct
6 Correct 13 ms 836 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 300 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 268 KB Output is correct
5 Correct 0 ms 292 KB Output is correct
6 Correct 13 ms 836 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 300 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 551 ms 202092 KB Output is correct
23 Correct 387 ms 12452 KB Output is correct
24 Correct 20 ms 8568 KB Output is correct
25 Correct 8 ms 6860 KB Output is correct
26 Correct 8 ms 6824 KB Output is correct
27 Correct 6 ms 6732 KB Output is correct
28 Correct 174 ms 10692 KB Output is correct
29 Correct 60 ms 7864 KB Output is correct
30 Correct 95 ms 3620 KB Output is correct
31 Correct 4 ms 6732 KB Output is correct
32 Correct 3 ms 4384 KB Output is correct
33 Correct 436 ms 201716 KB Output is correct
34 Correct 334 ms 171676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 107 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 107 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -