답안 #980890

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
980890 2024-05-12T15:07:23 Z Marcus 자매 도시 (APIO20_swap) C++17
17 / 100
2000 ms 10704 KB
#include <bits/stdc++.h>
using namespace std;
 
int n, m;
vector<tuple<int, int, int>> edge;
 
vector<int> link;
vector<int> volume;
vector<bool> swapable;
vector<int> degree;
 
int find(int x) {
    while (x != link[x]) x = link[x];
    return x;
}
 
bool same(int a, int b) {
    return find(a) == find(b);
}
 
void unite(int a, int b) {
    a = find(a); b = find(b);
    if (volume[a] < volume[b]) swap(a, b);
	volume[a] += volume[b];
	swapable[a] = swapable[a] || swapable[b];
    link[b] = a;
}
 
bool cmp(tuple<int, int, int> tul1, tuple<int, int, int> tul2)
{
	return (get<2>(tul1) < get<2>(tul2));
}
 
void init(int n1, int m1, vector<int> v, vector<int> u, vector<int> w) {
	n = n1;
	m = m1;
	for (int i=0; i<m; i++)
	{
		edge.push_back({v[i], u[i], w[i]});
	}
	sort(edge.begin(), edge.end(), cmp);
	link.resize(n, 0);
	volume.resize(n, 0);
	swapable.resize(n, 0);
	degree.resize(n, 0);
}
 
int getMinimumFuelCapacity(int x, int y) {
	for (int i=0; i<n; i++)
	{
	    link[i]=i;
	    volume[i]=1;
	    swapable[i]=0;
	    degree[i]=0;
	}
	for (int i=0; i<n; i++) {
		link[i] = i;
		volume[i] = 1;
	}
	for (auto e: edge)
	{
		int u = get<0>(e);
		int v = get<1>(e);
		int w = get<2>(e);
		degree[u]++; degree[v]++;
	    if (same(u, v) || degree[u] >= 3 || degree[v] >= 3) 
		{
			swapable[find(u)] = true;
	        swapable[find(v)] = true;
		}
		unite(u, v);
		if (same(x, y) && swapable[find(x)]) {return w;}
	}
	return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 31 ms 5584 KB Output is correct
10 Correct 45 ms 6788 KB Output is correct
11 Correct 46 ms 6904 KB Output is correct
12 Correct 48 ms 7116 KB Output is correct
13 Correct 45 ms 7220 KB Output is correct
14 Execution timed out 2057 ms 6092 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 2012 ms 6340 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 504 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 484 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 560 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 1 ms 348 KB Output is correct
10 Correct 31 ms 5584 KB Output is correct
11 Correct 45 ms 6788 KB Output is correct
12 Correct 46 ms 6904 KB Output is correct
13 Correct 48 ms 7116 KB Output is correct
14 Correct 45 ms 7220 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 504 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 484 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 560 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 5 ms 1308 KB Output is correct
35 Correct 47 ms 6860 KB Output is correct
36 Correct 47 ms 6832 KB Output is correct
37 Correct 47 ms 6836 KB Output is correct
38 Correct 46 ms 6860 KB Output is correct
39 Correct 46 ms 6700 KB Output is correct
40 Correct 43 ms 6156 KB Output is correct
41 Correct 56 ms 7224 KB Output is correct
42 Correct 47 ms 6856 KB Output is correct
43 Correct 40 ms 6856 KB Output is correct
44 Correct 52 ms 7112 KB Output is correct
45 Execution timed out 2072 ms 10704 KB Time limit exceeded
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 31 ms 5584 KB Output is correct
10 Correct 45 ms 6788 KB Output is correct
11 Correct 46 ms 6904 KB Output is correct
12 Correct 48 ms 7116 KB Output is correct
13 Correct 45 ms 7220 KB Output is correct
14 Execution timed out 2057 ms 6092 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 1 ms 348 KB Output is correct
10 Correct 31 ms 5584 KB Output is correct
11 Correct 45 ms 6788 KB Output is correct
12 Correct 46 ms 6904 KB Output is correct
13 Correct 48 ms 7116 KB Output is correct
14 Correct 45 ms 7220 KB Output is correct
15 Execution timed out 2057 ms 6092 KB Time limit exceeded
16 Halted 0 ms 0 KB -