답안 #1046392

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1046392 2024-08-06T13:47:19 Z xnqs Cheap flights (LMIO18_pigus_skrydziai) C++17
100 / 100
145 ms 29696 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <set>
#include <unordered_map> 

int gs, edg;
std::vector<std::vector<std::pair<int,int>>> adj_list;
std::vector<std::tuple<int,int,int>> edges;

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);
 
	for (int i = 0, a, b, c; i < edg; i++) {
		std::cin >> a >> b >> c;
		adj_list[a].emplace_back(b,c);
		adj_list[b].emplace_back(a,c);
		edges.emplace_back(std::min(a,b),std::max(a,b),c);
	}
 
	// 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
	std::sort(edges.begin(),edges.end());
	for (int i = 1; i <= gs; i++) {
		std::sort(adj_list[i].begin(),adj_list[i].end(),[](const std::pair<int,int>& a, const std::pair<int,int>& b) {
			return a.second > b.second;
		});
		if (adj_list[i].size()>=2) {
			auto [a, wa] = adj_list[i][0];
			auto [b, wb] = adj_list[i][1];

			auto it = std::lower_bound(edges.begin(),edges.end(),std::tuple<int,int,int>(std::min(a,b),std::max(a,b),0));
			if (it!=edges.end()&&std::get<0>(*it)==std::min(a,b)&&std::get<1>(*it)==std::max(a,b)) {
				ans = std::max(ans, (int64_t)wa + wb + std::get<2>(*it));
			}
		}
	}
 
	std::cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 344 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 4 ms 1116 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 348 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 1 ms 404 KB Output is correct
18 Correct 0 ms 420 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 344 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 4 ms 1116 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 348 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 1 ms 404 KB Output is correct
18 Correct 0 ms 420 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 145 ms 17396 KB Output is correct
23 Correct 110 ms 14432 KB Output is correct
24 Correct 5 ms 1176 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 54 ms 8208 KB Output is correct
29 Correct 20 ms 3856 KB Output is correct
30 Correct 33 ms 4108 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 104 ms 16236 KB Output is correct
34 Correct 70 ms 16384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 19216 KB Output is correct
2 Correct 102 ms 24292 KB Output is correct
3 Correct 31 ms 6928 KB Output is correct
4 Correct 61 ms 13792 KB Output is correct
5 Correct 139 ms 21816 KB Output is correct
6 Correct 16 ms 3964 KB Output is correct
7 Correct 58 ms 17556 KB Output is correct
8 Correct 69 ms 22788 KB Output is correct
9 Correct 2 ms 7512 KB Output is correct
10 Correct 17 ms 3864 KB Output is correct
11 Correct 53 ms 19000 KB Output is correct
12 Correct 33 ms 7424 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 21 ms 3860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 19216 KB Output is correct
2 Correct 102 ms 24292 KB Output is correct
3 Correct 31 ms 6928 KB Output is correct
4 Correct 61 ms 13792 KB Output is correct
5 Correct 139 ms 21816 KB Output is correct
6 Correct 16 ms 3964 KB Output is correct
7 Correct 58 ms 17556 KB Output is correct
8 Correct 69 ms 22788 KB Output is correct
9 Correct 2 ms 7512 KB Output is correct
10 Correct 17 ms 3864 KB Output is correct
11 Correct 53 ms 19000 KB Output is correct
12 Correct 33 ms 7424 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 21 ms 3860 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 0 ms 344 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 4 ms 1116 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 348 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 1 ms 404 KB Output is correct
32 Correct 0 ms 420 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 145 ms 17396 KB Output is correct
37 Correct 110 ms 14432 KB Output is correct
38 Correct 5 ms 1176 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 54 ms 8208 KB Output is correct
43 Correct 20 ms 3856 KB Output is correct
44 Correct 33 ms 4108 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 104 ms 16236 KB Output is correct
48 Correct 70 ms 16384 KB Output is correct
49 Correct 59 ms 12808 KB Output is correct
50 Correct 60 ms 11796 KB Output is correct
51 Correct 71 ms 15360 KB Output is correct
52 Correct 88 ms 19680 KB Output is correct
53 Correct 31 ms 10872 KB Output is correct
54 Correct 74 ms 19448 KB Output is correct
55 Correct 115 ms 29696 KB Output is correct
56 Correct 80 ms 18204 KB Output is correct
57 Correct 72 ms 22900 KB Output is correct
58 Correct 40 ms 10280 KB Output is correct
59 Correct 104 ms 20220 KB Output is correct
60 Correct 83 ms 18692 KB Output is correct
61 Correct 79 ms 16072 KB Output is correct