답안 #1046390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1046390 2024-08-06T13:46:53 Z xnqs Cheap flights (LMIO18_pigus_skrydziai) C++17
16 / 100
136 ms 23352 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 0 ms 344 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 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 Incorrect 0 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 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 Incorrect 0 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 20048 KB Output is correct
2 Correct 136 ms 23040 KB Output is correct
3 Correct 31 ms 6928 KB Output is correct
4 Correct 64 ms 15108 KB Output is correct
5 Correct 133 ms 22056 KB Output is correct
6 Correct 20 ms 3856 KB Output is correct
7 Correct 57 ms 17412 KB Output is correct
8 Correct 72 ms 23352 KB Output is correct
9 Correct 2 ms 7512 KB Output is correct
10 Correct 17 ms 3852 KB Output is correct
11 Correct 54 ms 18788 KB Output is correct
12 Correct 33 ms 7952 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 24 ms 3860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 20048 KB Output is correct
2 Correct 136 ms 23040 KB Output is correct
3 Correct 31 ms 6928 KB Output is correct
4 Correct 64 ms 15108 KB Output is correct
5 Correct 133 ms 22056 KB Output is correct
6 Correct 20 ms 3856 KB Output is correct
7 Correct 57 ms 17412 KB Output is correct
8 Correct 72 ms 23352 KB Output is correct
9 Correct 2 ms 7512 KB Output is correct
10 Correct 17 ms 3852 KB Output is correct
11 Correct 54 ms 18788 KB Output is correct
12 Correct 33 ms 7952 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 24 ms 3860 KB Output is correct
15 Correct 0 ms 344 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 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 Incorrect 0 ms 348 KB Output isn't correct
25 Halted 0 ms 0 KB -