답안 #851158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
851158 2023-09-18T16:44:16 Z pakapu Cheap flights (LMIO18_pigus_skrydziai) C++17
0 / 100
78 ms 21416 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int ans = 0;
int curr_flag = 0;

vector<int> cost;
vector<int> calculated;
vector<vector<pair<int, int>>> g;

int dfs(int u, int depth) {
	if(depth >= 2) {
		return 0;
	}
	if(depth == 1) {
		for(auto v : g[u]) {
			if(calculated[v.first] != curr_flag) {
				continue;
			}
			//cout << v.first << ' ' << u << '\n';
			//cout << cost[v.first] << ' ' << cost[u] << ' ' << v.second << '\n';
			ans = max(ans, cost[v.first] + cost[u] + v.second);
		}
		return 0;
	}

	int curr = 0;

	for(auto v : g[u]) {
		cost[v.first] = v.second;
		calculated[v.first] = curr_flag;
		curr += v.second;
		dfs(v.first, depth + 1);
	}

	return curr;
}


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, m;
	cin >> n >> m;

	cost = vector<int>(n);
	calculated = vector<int>(n);
	g = vector<vector<pair<int, int>>>(n);

	for(int i = 0; i < m; i++) {
		int from, to, w;
		cin >> from >> to >> w;
		from--;
		to--;

		g[from].push_back(make_pair(to, w));
		g[to].push_back(make_pair(from, w));
	}

	ans = 0;
	for(int i = 0; i < n; i++) {
		curr_flag = i;
		int curr = dfs(i, 0);
		ans = max(ans, curr);
	}


	cout << ans << '\n';

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 78 ms 21416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 78 ms 21416 KB Output isn't correct
2 Halted 0 ms 0 KB -