Submission #979800

# Submission time Handle Problem Language Result Execution time Memory
979800 2024-05-11T11:39:56 Z Marcus Swapping Cities (APIO20_swap) C++17
6 / 100
89 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);
	visited.resize(n);
	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 (m == (n-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 1 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 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 30 ms 8636 KB Output is correct
10 Correct 49 ms 10676 KB Output is correct
11 Correct 48 ms 9652 KB Output is correct
12 Correct 38 ms 10180 KB Output is correct
13 Correct 41 ms 11452 KB Output is correct
14 Correct 34 ms 8120 KB Output is correct
15 Correct 82 ms 13280 KB Output is correct
16 Correct 80 ms 12032 KB Output is correct
17 Correct 80 ms 12984 KB Output is correct
18 Correct 81 ms 13752 KB Output is correct
19 Correct 43 ms 5712 KB Output is correct
20 Correct 82 ms 15316 KB Output is correct
21 Correct 84 ms 15304 KB Output is correct
22 Correct 88 ms 15940 KB Output is correct
23 Correct 89 ms 16060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 82 ms 12272 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 344 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 30 ms 8636 KB Output is correct
10 Correct 49 ms 10676 KB Output is correct
11 Correct 48 ms 9652 KB Output is correct
12 Correct 38 ms 10180 KB Output is correct
13 Correct 41 ms 11452 KB Output is correct
14 Correct 34 ms 8120 KB Output is correct
15 Correct 82 ms 13280 KB Output is correct
16 Correct 80 ms 12032 KB Output is correct
17 Correct 80 ms 12984 KB Output is correct
18 Correct 81 ms 13752 KB Output is correct
19 Incorrect 82 ms 12272 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -