Submission #1046308

# Submission time Handle Problem Language Result Execution time Memory
1046308 2024-08-06T12:45:28 Z xnqs Cheap flights (LMIO18_pigus_skrydziai) C++17
28 / 100
3000 ms 57984 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <set>
 
int gs, edg;
std::vector<std::set<std::pair<int,int>>> adj_list;
 
int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
 
	std::cin >> gs >> edg;
	adj_list.resize(gs+1);

	std::priority_queue<int> q;
	for (int i = 0, a, b, c; i < edg; i++) {
		std::cin >> a >> b >> c;
		adj_list[a].emplace(b,c);
		adj_list[b].emplace(a,c);
		q.emplace(c);
	}

	int64_t max_tri = 0;
	for (int cnt = 0; !q.empty() && cnt < 3; cnt++) {
		max_tri += q.top();
		q.pop();
	}
 
	// try all star graphs
	int64_t ans = 0;
	for (int i = 1; i <= gs; i++) {
		int64_t cand = 0;
		for (const auto& [j, w] : adj_list[i]) {
			cand += w;
		}
		ans = std::max(ans,cand);
	}
 
	// try all "triangle" cycles
	if (ans<=max_tri)
	for (int i = 1; i <= gs; i++) {
		if (adj_list[i].size()<2) {
			continue;
		}
		for (const auto& [j, wj] : adj_list[i]) {
			if (j<i) {
				continue;
			}
			for (const auto& [k, wk] : adj_list[j]) {
				if (k<j) {
					continue;
				}
				if (k==i) {
					continue;
				}
 
				auto it = adj_list[k].lower_bound(std::pair<int,int>(i,0));
				if (it!=adj_list[k].end()&&it->first==i) {
					//std::cout << i << " " << j << " " << k << "\n";
					//std::cout << wj << " " << wk << " " << it->second << "\n";
					ans = std::max(ans, static_cast<int64_t>(wj)+wk+it->second);
				}
			}
		}
	}
 
	std::cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 2396 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 428 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 2396 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 428 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 485 ms 49468 KB Output is correct
23 Correct 189 ms 57984 KB Output is correct
24 Correct 34 ms 2664 KB Output is correct
25 Correct 4 ms 948 KB Output is correct
26 Correct 4 ms 1116 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 128 ms 23488 KB Output is correct
29 Correct 43 ms 9160 KB Output is correct
30 Correct 74 ms 14792 KB Output is correct
31 Correct 0 ms 600 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 184 ms 56608 KB Output is correct
34 Execution timed out 3035 ms 49888 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 29068 KB Output is correct
2 Correct 130 ms 43664 KB Output is correct
3 Correct 31 ms 14924 KB Output is correct
4 Correct 76 ms 28796 KB Output is correct
5 Correct 182 ms 39104 KB Output is correct
6 Correct 31 ms 12500 KB Output is correct
7 Correct 51 ms 37492 KB Output is correct
8 Correct 63 ms 43712 KB Output is correct
9 Correct 3 ms 14428 KB Output is correct
10 Correct 32 ms 12688 KB Output is correct
11 Correct 101 ms 36800 KB Output is correct
12 Correct 65 ms 24776 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 52 ms 10196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 29068 KB Output is correct
2 Correct 130 ms 43664 KB Output is correct
3 Correct 31 ms 14924 KB Output is correct
4 Correct 76 ms 28796 KB Output is correct
5 Correct 182 ms 39104 KB Output is correct
6 Correct 31 ms 12500 KB Output is correct
7 Correct 51 ms 37492 KB Output is correct
8 Correct 63 ms 43712 KB Output is correct
9 Correct 3 ms 14428 KB Output is correct
10 Correct 32 ms 12688 KB Output is correct
11 Correct 101 ms 36800 KB Output is correct
12 Correct 65 ms 24776 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 52 ms 10196 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 6 ms 2396 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 428 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 485 ms 49468 KB Output is correct
37 Correct 189 ms 57984 KB Output is correct
38 Correct 34 ms 2664 KB Output is correct
39 Correct 4 ms 948 KB Output is correct
40 Correct 4 ms 1116 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 128 ms 23488 KB Output is correct
43 Correct 43 ms 9160 KB Output is correct
44 Correct 74 ms 14792 KB Output is correct
45 Correct 0 ms 600 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 184 ms 56608 KB Output is correct
48 Execution timed out 3035 ms 49888 KB Time limit exceeded
49 Halted 0 ms 0 KB -