Submission #851163

# Submission time Handle Problem Language Result Execution time Memory
851163 2023-09-18T17:24:09 Z pakapu Cheap flights (LMIO18_pigus_skrydziai) C++17
12 / 100
3000 ms 34424 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int ans = 0;

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

int dfs(int u, int depth, int flag) {
	if(depth >= 1) {
		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;
}

void check_triangles(int flag) {
	for(auto c : edges) {
		if(calculated[get<0>(c)] == flag && calculated[get<1>(c)] == flag) {
			//cout << get<0>(c) << ' ' << get<1>(c) << '\n';
			ans = max(ans, cost[get<0>(c)] + cost[get<1>(c)] + get<2>(c));
		}
	}
}

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));
		edges.push_back(make_tuple(from, to, w));
	}

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


	cout << ans << '\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 16 ms 1884 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 500 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 16 ms 1884 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 500 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Execution timed out 3017 ms 34424 KB Time limit exceeded
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3049 ms 26936 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3049 ms 26936 KB Time limit exceeded
2 Halted 0 ms 0 KB -