Submission #979796

# Submission time Handle Problem Language Result Execution time Memory
979796 2024-05-11T11:26:49 Z Marcus Swapping Cities (APIO20_swap) C++17
6 / 100
86 ms 16060 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;
	vector<pair<int, int>> edge;
}

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));

	if (subtask2::execution) 
	{
		for (auto u: adj[0]) 
		{
			subtask2::edge.push_back({u.second, u.first});
		}
		sort(subtask2::edge.begin(), subtask2::edge.end());
		subtask2::edge.erase(subtask2::edge.begin()+3, subtask2::edge.end());
	}
}

int getMinimumFuelCapacity(int x, int y){
	if (subtask2::execution) 
	{
		if (n < 4) return -1;
		gas = max(adj[x][0].second, adj[y][0].second);
		for (auto u: subtask2::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 348 KB Output is correct
4 Correct 0 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 32 ms 8632 KB Output is correct
10 Correct 40 ms 10820 KB Output is correct
11 Correct 36 ms 9728 KB Output is correct
12 Correct 49 ms 10040 KB Output is correct
13 Correct 39 ms 11456 KB Output is correct
14 Correct 34 ms 8128 KB Output is correct
15 Correct 80 ms 13280 KB Output is correct
16 Correct 82 ms 12240 KB Output is correct
17 Correct 81 ms 12984 KB Output is correct
18 Correct 82 ms 13764 KB Output is correct
19 Correct 42 ms 5712 KB Output is correct
20 Correct 82 ms 15312 KB Output is correct
21 Correct 82 ms 15304 KB Output is correct
22 Correct 85 ms 16060 KB Output is correct
23 Correct 86 ms 16060 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 Incorrect 78 ms 12464 KB Output isn't correct
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 348 KB Output is correct
4 Correct 0 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 348 KB Output is correct
4 Correct 0 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 32 ms 8632 KB Output is correct
10 Correct 40 ms 10820 KB Output is correct
11 Correct 36 ms 9728 KB Output is correct
12 Correct 49 ms 10040 KB Output is correct
13 Correct 39 ms 11456 KB Output is correct
14 Correct 34 ms 8128 KB Output is correct
15 Correct 80 ms 13280 KB Output is correct
16 Correct 82 ms 12240 KB Output is correct
17 Correct 81 ms 12984 KB Output is correct
18 Correct 82 ms 13764 KB Output is correct
19 Incorrect 78 ms 12464 KB Output isn't correct
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 -