답안 #657027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
657027 2022-11-08T18:53:50 Z 600Mihnea 자매 도시 (APIO20_swap) C++17
0 / 100
2000 ms 6436 KB
#include "swap.h"

#include <bits/stdc++.h>

using namespace std;

mt19937 rng(0);

const int INF = (int) 1e9 + 7;
int n;
int m;
vector<int> t;
vector<int> is_line;
vector<bool> is_endpoint;

int root(int a) {
	if (t[a] == a) {
		return t[a];
	} else {
		return root(t[a]);
	}
}

void join(int a, int b, int val) {
	int x = a, y = b;
	a = root(a);
	b = root(b);
	if (a == b) {
		is_line[a] = 0;
		return;
	}
	if (rng() & 1) {
		swap(a, b);
	}
	if (is_line[a] && is_line[b] && is_endpoint[x] && is_endpoint[y]) {
		is_line[a] = 1;
		if (root(x) != x) {
			is_endpoint[x] = 0;
		}
		if (root(y) != y) {
			is_endpoint[y] = 0;
		}
	} else {
		is_line[a] = 0;
	}
	t[b] = a;
}

void clr() {
	t.resize(n);
	is_line.resize(n);
	is_endpoint.resize(n);
	for (int i = 0; i < n; i++) {
		t[i] = i;
		is_line[i] = 1;
		is_endpoint[i] = 1;
	}
}

struct Edge {
	int a;
	int b;
	int w;
};

bool operator < (Edge first, Edge second) {
	return first.w < second.w;
}

vector<Edge> edges;

void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
	n = N;
	m = M;
	assert((int) U.size() == m);
	assert((int) V.size() == m);
	assert((int) W.size() == m);
	
	edges.clear();
	for (int i = 0; i < m; i++) {
		edges.push_back({U[i], V[i], W[i]});
	}
	sort(edges.begin(), edges.end());
}


int getMinimumFuelCapacity(int x, int y) {
	clr();
	for (auto &edge : edges) {
		int a = edge.a;
		int b = edge.b;
		int w = edge.w;
		join(a, b, w);
		//cout << a << " " << b << " | " << w << " and I care about " << x << " " << y << "\n";
		if (root(x) == root(y) && !is_line[root(x)]) {
			return w; 
		}
	}
	return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 41 ms 5444 KB Output is correct
10 Correct 52 ms 6128 KB Output is correct
11 Correct 63 ms 6132 KB Output is correct
12 Correct 67 ms 6436 KB Output is correct
13 Execution timed out 2072 ms 6340 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Execution timed out 2051 ms 5876 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Incorrect 2 ms 340 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 41 ms 5444 KB Output is correct
11 Correct 52 ms 6128 KB Output is correct
12 Correct 63 ms 6132 KB Output is correct
13 Correct 67 ms 6436 KB Output is correct
14 Execution timed out 2072 ms 6340 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 41 ms 5444 KB Output is correct
10 Correct 52 ms 6128 KB Output is correct
11 Correct 63 ms 6132 KB Output is correct
12 Correct 67 ms 6436 KB Output is correct
13 Execution timed out 2072 ms 6340 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 41 ms 5444 KB Output is correct
11 Correct 52 ms 6128 KB Output is correct
12 Correct 63 ms 6132 KB Output is correct
13 Correct 67 ms 6436 KB Output is correct
14 Execution timed out 2072 ms 6340 KB Time limit exceeded
15 Halted 0 ms 0 KB -