Submission #499098

# Submission time Handle Problem Language Result Execution time Memory
499098 2021-12-27T08:38:30 Z aurims Cheap flights (LMIO18_pigus_skrydziai) C++14
37 / 100
569 ms 262148 KB
#include <bits/stdc++.h>
#define debug cout << "alio\n"
#define pb push_back
#define ll long long
#define MAX (int)3e5
using namespace std;

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

};
vector<miestas> miestai;

vector<int> adj[MAX];
map<pair<int, int>, int> p;

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:56:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   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 3 ms 7328 KB Output is correct
2 Correct 5 ms 7340 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Correct 4 ms 7244 KB Output is correct
5 Correct 6 ms 7340 KB Output is correct
6 Correct 18 ms 8012 KB Output is correct
7 Correct 4 ms 7244 KB Output is correct
8 Correct 4 ms 7332 KB Output is correct
9 Correct 4 ms 7244 KB Output is correct
10 Correct 4 ms 7244 KB Output is correct
11 Correct 4 ms 7500 KB Output is correct
12 Correct 4 ms 7500 KB Output is correct
13 Correct 4 ms 7500 KB Output is correct
14 Correct 4 ms 7244 KB Output is correct
15 Correct 4 ms 7332 KB Output is correct
16 Correct 4 ms 7340 KB Output is correct
17 Correct 4 ms 7244 KB Output is correct
18 Correct 6 ms 7440 KB Output is correct
19 Correct 6 ms 7736 KB Output is correct
20 Correct 4 ms 7592 KB Output is correct
21 Correct 5 ms 7336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7328 KB Output is correct
2 Correct 5 ms 7340 KB Output is correct
3 Correct 5 ms 7252 KB Output is correct
4 Correct 4 ms 7244 KB Output is correct
5 Correct 6 ms 7340 KB Output is correct
6 Correct 18 ms 8012 KB Output is correct
7 Correct 4 ms 7244 KB Output is correct
8 Correct 4 ms 7332 KB Output is correct
9 Correct 4 ms 7244 KB Output is correct
10 Correct 4 ms 7244 KB Output is correct
11 Correct 4 ms 7500 KB Output is correct
12 Correct 4 ms 7500 KB Output is correct
13 Correct 4 ms 7500 KB Output is correct
14 Correct 4 ms 7244 KB Output is correct
15 Correct 4 ms 7332 KB Output is correct
16 Correct 4 ms 7340 KB Output is correct
17 Correct 4 ms 7244 KB Output is correct
18 Correct 6 ms 7440 KB Output is correct
19 Correct 6 ms 7736 KB Output is correct
20 Correct 4 ms 7592 KB Output is correct
21 Correct 5 ms 7336 KB Output is correct
22 Correct 569 ms 213460 KB Output is correct
23 Correct 434 ms 23712 KB Output is correct
24 Correct 23 ms 15684 KB Output is correct
25 Correct 14 ms 13900 KB Output is correct
26 Correct 14 ms 13884 KB Output is correct
27 Correct 9 ms 13772 KB Output is correct
28 Correct 236 ms 20932 KB Output is correct
29 Correct 60 ms 15624 KB Output is correct
30 Correct 108 ms 12552 KB Output is correct
31 Correct 7 ms 13772 KB Output is correct
32 Correct 6 ms 11444 KB Output is correct
33 Correct 462 ms 213180 KB Output is correct
34 Correct 339 ms 183072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 103 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 103 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -