Submission #498917

# Submission time Handle Problem Language Result Execution time Memory
498917 2021-12-26T17:00:29 Z aurims Cheap flights (LMIO18_pigus_skrydziai) C++14
0 / 100
121 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
		for(int j = 0; j < miestai[i].kaimynai.size()-1; j++)
		{
			int kaim1 = miestai[i].kaimynai[j];
			int kaim2 = miestai[i].kaimynai[j+1];
			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];
		}
		if(sum_zv > sum_tr)
			if(sum_zv > mx)
				mx = sum_zv;
		else
			if(sum_tr > mx)
				mx = sum_tr;
	}
	cout << mx << '\n';
}

Compilation message

pigus_skrydziai.cpp: In function 'int main()':
pigus_skrydziai.cpp:51:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for(int j = 0; j < miestai[i].kaimynai.size()-1; j++)
      |                  ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pigus_skrydziai.cpp:58:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   58 |   if(sum_zv > sum_tr)
      |     ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 121 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 121 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -