Submission #498826

# Submission time Handle Problem Language Result Execution time Memory
498826 2021-12-26T12:14:18 Z aurims Cheap flights (LMIO18_pigus_skrydziai) C++14
0 / 100
102 ms 262148 KB
#include <bits/stdc++.h>
#define debug cout << "alio\n";
#define pb push_back
#define ll long long
#define MAXN 5000
#define ff first
#define ss second
using namespace std;

/* 
input
5 4
1 2 1
1 3 2
1 4 1
2 4 1
*/

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;
	}
	int mx = -1;
	// perrenkam visas zvaigzdes
	for(int i = 0; i < N; i++)
	{
		int sum = 0;
		for(int sidx : miestai[i].kaimynai)
		{
			sum += miestai[i].pelnas[sidx];
		}
		if(sum > mx)
			mx = sum;
	}
	// perrenkam visus trikampius
	for(int i = 0; i < N; i++)
	{
		int sum = 0;
		int mxind_1 = 0;
		int mxind_2 = 0;
		for(int sidx : miestai[i].kaimynai)
		{
			if(miestai[i].pelnas[sidx] > miestai[i].pelnas[mxind_1])
			{
				cout << mxind_1 << '\n';
				mxind_1 = sidx;
			}
			else if(miestai[i].pelnas[sidx] > miestai[i].pelnas[mxind_2])
			{
				cout << mxind_2 << '\n';
				mxind_2 = sidx;
			}
		}
		if(miestai[mxind_1].pelnas[mxind_2] != -1 && miestai[i].pelnas[mxind_1] != -1 && miestai[i].pelnas[mxind_2] != -1)
		{
			sum += miestai[mxind_1].pelnas[mxind_2] + miestai[i].pelnas[mxind_1] + miestai[i].pelnas[mxind_2];
		}
		if(sum > mx)
			mx = sum;
	}
	cout << mx << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 102 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 102 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -