답안 #1069403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1069403 2024-08-21T21:43:10 Z pawned 자매 도시 (APIO20_swap) C++17
17 / 100
2000 ms 25888 KB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

#include "swap.h"

const int MAX = 1e5 + 5;

int N, M;

vector<ii> adj[MAX];	// {vertex, dist}

void init(int N_g, int M_g, vi U_g, vi V_g, vi W_g) {
	N = N_g;
	M = M_g;
	for (int i = 0; i < M; i++) {
		adj[U_g[i]].pb({V_g[i], W_g[i]});
		adj[V_g[i]].pb({U_g[i], W_g[i]});
	}
}

bool check(int cut, int X, int Y) {
	vi adjc[N];
	for (int i = 0; i < N; i++) {
		for (ii p : adj[i]) {
			if (p.se <= cut)
				adjc[i].pb(p.fi);
		}
	}
	vector<bool> vis(N, false);
	queue<int> q;
	q.push(X);
	vis[X] = true;
	while (!q.empty()) {
		int x = q.front();
		q.pop();
		for (int y : adjc[x]) {
			if (!vis[y]) {
				q.push(y);
				vis[y] = true;
			}
		}
	}
	if (!vis[Y])
		return false;
	vi adjd[N];
	for (int i = 0; i < N; i++) {
		if (!vis[i])
			continue;
		for (int x : adjc[i]) {
			if (vis[x])
				adjd[i].pb(x);
		}
	}
	int cnte = 0;	// number of edges
	int sz = 0;	// number of vertices
	for (int i = 0; i < N; i++) {
		cnte += adjd[i].size();
		if (adjd[i].size() >= 1)
			sz++;
	}
	cnte /= 2;
//	cout<<"sz, cnte: "<<sz<<" "<<cnte<<endl;
	if (cnte > sz - 1)	// has a cycle
		return true;
	for (int i = 0; i < N; i++) {
		if (adjd[i].size() >= 3)
			return true;
	}
	return false;
}

int getMinimumFuelCapacity(int X, int Y) {
//	cout<<check(3, X, Y)<<endl;
	int low = 0;
	int high = 1e9 + 5;
	int ans = -1;	// minimum so can pass
	while (low <= high) {	// false, false, false, true, true, true
		int mid = (low + high) / 2;
		if (check(mid, X, Y)) {
			ans = mid;
			high = mid - 1;
		}
		else {
			low = mid + 1;
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 9 ms 2844 KB Output is correct
5 Correct 10 ms 2920 KB Output is correct
6 Correct 11 ms 2908 KB Output is correct
7 Correct 12 ms 2940 KB Output is correct
8 Correct 13 ms 2904 KB Output is correct
9 Correct 474 ms 14760 KB Output is correct
10 Correct 1090 ms 17376 KB Output is correct
11 Correct 1487 ms 17136 KB Output is correct
12 Correct 1437 ms 17852 KB Output is correct
13 Correct 1756 ms 17848 KB Output is correct
14 Execution timed out 2020 ms 14776 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Execution timed out 2065 ms 21116 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 9 ms 2844 KB Output is correct
5 Correct 10 ms 2920 KB Output is correct
6 Correct 11 ms 2908 KB Output is correct
7 Correct 12 ms 2940 KB Output is correct
8 Correct 13 ms 2904 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 8 ms 2908 KB Output is correct
11 Correct 13 ms 2932 KB Output is correct
12 Correct 12 ms 2908 KB Output is correct
13 Correct 11 ms 2904 KB Output is correct
14 Correct 10 ms 2908 KB Output is correct
15 Correct 10 ms 2908 KB Output is correct
16 Correct 13 ms 2908 KB Output is correct
17 Correct 19 ms 2948 KB Output is correct
18 Correct 11 ms 2816 KB Output is correct
19 Correct 7 ms 2908 KB Output is correct
20 Correct 12 ms 2908 KB Output is correct
21 Correct 11 ms 2908 KB Output is correct
22 Correct 5 ms 2924 KB Output is correct
23 Correct 9 ms 2916 KB Output is correct
24 Correct 13 ms 2840 KB Output is correct
25 Correct 11 ms 3008 KB Output is correct
26 Correct 22 ms 2904 KB Output is correct
27 Correct 11 ms 2904 KB Output is correct
28 Correct 14 ms 3000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 9 ms 2844 KB Output is correct
6 Correct 10 ms 2920 KB Output is correct
7 Correct 11 ms 2908 KB Output is correct
8 Correct 12 ms 2940 KB Output is correct
9 Correct 13 ms 2904 KB Output is correct
10 Correct 474 ms 14760 KB Output is correct
11 Correct 1090 ms 17376 KB Output is correct
12 Correct 1487 ms 17136 KB Output is correct
13 Correct 1437 ms 17852 KB Output is correct
14 Correct 1756 ms 17848 KB Output is correct
15 Correct 8 ms 2908 KB Output is correct
16 Correct 13 ms 2932 KB Output is correct
17 Correct 12 ms 2908 KB Output is correct
18 Correct 11 ms 2904 KB Output is correct
19 Correct 10 ms 2908 KB Output is correct
20 Correct 10 ms 2908 KB Output is correct
21 Correct 13 ms 2908 KB Output is correct
22 Correct 19 ms 2948 KB Output is correct
23 Correct 11 ms 2816 KB Output is correct
24 Correct 7 ms 2908 KB Output is correct
25 Correct 12 ms 2908 KB Output is correct
26 Correct 11 ms 2908 KB Output is correct
27 Correct 5 ms 2924 KB Output is correct
28 Correct 9 ms 2916 KB Output is correct
29 Correct 13 ms 2840 KB Output is correct
30 Correct 11 ms 3008 KB Output is correct
31 Correct 22 ms 2904 KB Output is correct
32 Correct 11 ms 2904 KB Output is correct
33 Correct 14 ms 3000 KB Output is correct
34 Correct 39 ms 4956 KB Output is correct
35 Correct 1753 ms 19640 KB Output is correct
36 Correct 1595 ms 19876 KB Output is correct
37 Correct 1563 ms 19896 KB Output is correct
38 Correct 1671 ms 19412 KB Output is correct
39 Correct 1744 ms 19604 KB Output is correct
40 Correct 1958 ms 18380 KB Output is correct
41 Correct 1441 ms 20148 KB Output is correct
42 Correct 1811 ms 19648 KB Output is correct
43 Correct 1611 ms 19764 KB Output is correct
44 Correct 1279 ms 20704 KB Output is correct
45 Correct 1453 ms 20628 KB Output is correct
46 Correct 1662 ms 19872 KB Output is correct
47 Correct 1687 ms 19848 KB Output is correct
48 Correct 1714 ms 20600 KB Output is correct
49 Correct 100 ms 14104 KB Output is correct
50 Correct 208 ms 11464 KB Output is correct
51 Correct 1030 ms 17976 KB Output is correct
52 Correct 1568 ms 23764 KB Output is correct
53 Correct 1413 ms 24664 KB Output is correct
54 Execution timed out 2036 ms 25888 KB Time limit exceeded
55 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 9 ms 2844 KB Output is correct
5 Correct 10 ms 2920 KB Output is correct
6 Correct 11 ms 2908 KB Output is correct
7 Correct 12 ms 2940 KB Output is correct
8 Correct 13 ms 2904 KB Output is correct
9 Correct 474 ms 14760 KB Output is correct
10 Correct 1090 ms 17376 KB Output is correct
11 Correct 1487 ms 17136 KB Output is correct
12 Correct 1437 ms 17852 KB Output is correct
13 Correct 1756 ms 17848 KB Output is correct
14 Execution timed out 2020 ms 14776 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 9 ms 2844 KB Output is correct
6 Correct 10 ms 2920 KB Output is correct
7 Correct 11 ms 2908 KB Output is correct
8 Correct 12 ms 2940 KB Output is correct
9 Correct 13 ms 2904 KB Output is correct
10 Correct 474 ms 14760 KB Output is correct
11 Correct 1090 ms 17376 KB Output is correct
12 Correct 1487 ms 17136 KB Output is correct
13 Correct 1437 ms 17852 KB Output is correct
14 Correct 1756 ms 17848 KB Output is correct
15 Execution timed out 2020 ms 14776 KB Time limit exceeded
16 Halted 0 ms 0 KB -