Submission #979788

# Submission time Handle Problem Language Result Execution time Memory
979788 2024-05-11T11:13:18 Z Marcus Swapping Cities (APIO20_swap) C++17
6 / 100
2000 ms 16300 KB
#include <swap.h>
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<pair<int, int>>> adj;
vector<bool> visited;

bool cycle = false;
int gas = 0;
void dfs(int s, int v)
{
	if (visited[s]) return;
	visited[s] = true;
	for (auto u: adj[s])
	{
		if (visited[u.first] && u.first != v) cycle = true;
		gas = max(gas, u.second);
		dfs(u.first, s);
	}
}

namespace subtask2 {
	bool nodes = false;
	bool variation = false;
	bool execution = false;
}

void init(int n1, int m1, vector<int> v, vector<int> u, vector<int> w) {
	n = n1;
	m = m1;
	adj.resize(n+1);
	visited.resize(n+1);
	for (int i=0; i<m; i++)
	{
		adj[v[i]].push_back({u[i], w[i]});
		adj[u[i]].push_back({v[i], w[i]});
	}

	//confirmation for subtask2
	if (m1 == (n1-1)) {subtask2::nodes = true;}
	for (auto s: v) {if (s != 0) {subtask2::variation = true;}}
	subtask2::execution = (subtask2::nodes && !(subtask2::variation));
}

int getMinimumFuelCapacity(int x, int y){
	if (subtask2::execution) 
	{
		if (n < 4) return -1;
		vector<pair<int, int>> edge;
		for (auto u: adj[0]) 
		{
			edge.push_back({u.second, u.first});
			if (u.first == x || u.first == y) {gas = max(gas, u.second);}
		}
		sort(edge.begin(), edge.end());
		edge.erase(edge.begin()+3, edge.end());
		for (auto u: edge)
		{
			if (u.second != x && u.second != y) 
			{
				return max(u.first, gas);
			}
		}
	}
	dfs(1, 0);
	return (cycle ? gas : -1);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 31 ms 8640 KB Output is correct
10 Correct 38 ms 10732 KB Output is correct
11 Correct 42 ms 9792 KB Output is correct
12 Correct 39 ms 10168 KB Output is correct
13 Correct 41 ms 11244 KB Output is correct
14 Correct 36 ms 8272 KB Output is correct
15 Correct 80 ms 13248 KB Output is correct
16 Correct 86 ms 12036 KB Output is correct
17 Correct 100 ms 12988 KB Output is correct
18 Correct 92 ms 13648 KB Output is correct
19 Correct 42 ms 5720 KB Output is correct
20 Correct 80 ms 15544 KB Output is correct
21 Correct 82 ms 15212 KB Output is correct
22 Correct 89 ms 16300 KB Output is correct
23 Correct 87 ms 16068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 2027 ms 11692 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 31 ms 8640 KB Output is correct
10 Correct 38 ms 10732 KB Output is correct
11 Correct 42 ms 9792 KB Output is correct
12 Correct 39 ms 10168 KB Output is correct
13 Correct 41 ms 11244 KB Output is correct
14 Correct 36 ms 8272 KB Output is correct
15 Correct 80 ms 13248 KB Output is correct
16 Correct 86 ms 12036 KB Output is correct
17 Correct 100 ms 12988 KB Output is correct
18 Correct 92 ms 13648 KB Output is correct
19 Execution timed out 2027 ms 11692 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -