답안 #851159

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
851159 2023-09-18T16:52:27 Z pakapu Cheap flights (LMIO18_pigus_skrydziai) C++17
37 / 100
3000 ms 32196 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int ans = 0;

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

int dfs(int u, int depth, int flag) {
	if(depth >= 2) {
		return 0;
	}
	if(depth == 1) {
		for(auto v : g[u]) {
			if(calculated[v.first] == flag) {
				//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] = flag;
		curr += v.second;
		dfs(v.first, depth + 1, flag);
	}

	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, -1);
	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++) {
		int curr = dfs(i, 0, i + 1);
		ans = max(ans, curr);
	}


	cout << ans << '\n';

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 19 ms 1116 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 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 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 19 ms 1116 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 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 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 372 KB Output is correct
22 Correct 546 ms 22612 KB Output is correct
23 Correct 2212 ms 16740 KB Output is correct
24 Correct 7 ms 1368 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 3 ms 604 KB Output is correct
28 Correct 158 ms 9384 KB Output is correct
29 Correct 231 ms 4188 KB Output is correct
30 Correct 455 ms 5032 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1747 ms 20800 KB Output is correct
34 Correct 1466 ms 19796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 21588 KB Output is correct
2 Correct 178 ms 32196 KB Output is correct
3 Correct 31 ms 10844 KB Output is correct
4 Correct 71 ms 21564 KB Output is correct
5 Correct 170 ms 28032 KB Output is correct
6 Correct 252 ms 5720 KB Output is correct
7 Correct 63 ms 26344 KB Output is correct
8 Correct 75 ms 30548 KB Output is correct
9 Correct 5 ms 12120 KB Output is correct
10 Correct 253 ms 5800 KB Output is correct
11 Execution timed out 3043 ms 25284 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 21588 KB Output is correct
2 Correct 178 ms 32196 KB Output is correct
3 Correct 31 ms 10844 KB Output is correct
4 Correct 71 ms 21564 KB Output is correct
5 Correct 170 ms 28032 KB Output is correct
6 Correct 252 ms 5720 KB Output is correct
7 Correct 63 ms 26344 KB Output is correct
8 Correct 75 ms 30548 KB Output is correct
9 Correct 5 ms 12120 KB Output is correct
10 Correct 253 ms 5800 KB Output is correct
11 Execution timed out 3043 ms 25284 KB Time limit exceeded
12 Halted 0 ms 0 KB -