結果

問題 No.1382 Travel in Mitaru city
ユーザー tkmst201tkmst201
提出日時 2021-02-10 14:47:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,912 bytes
コンパイル時間 3,581 ms
コンパイル使用メモリ 208,396 KB
実行使用メモリ 9,680 KB
最終ジャッジ日時 2023-09-22 09:00:32
合計ジャッジ時間 11,991 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 29 ms
4,848 KB
testcase_07 AC 24 ms
4,700 KB
testcase_08 AC 13 ms
4,380 KB
testcase_09 AC 32 ms
5,008 KB
testcase_10 AC 29 ms
4,868 KB
testcase_11 AC 45 ms
7,096 KB
testcase_12 AC 51 ms
7,004 KB
testcase_13 AC 50 ms
7,008 KB
testcase_14 AC 43 ms
6,772 KB
testcase_15 AC 44 ms
6,980 KB
testcase_16 AC 72 ms
9,444 KB
testcase_17 AC 71 ms
9,396 KB
testcase_18 AC 74 ms
9,356 KB
testcase_19 AC 76 ms
9,392 KB
testcase_20 AC 75 ms
9,384 KB
testcase_21 AC 82 ms
9,420 KB
testcase_22 AC 75 ms
9,432 KB
testcase_23 AC 70 ms
9,392 KB
testcase_24 AC 72 ms
9,356 KB
testcase_25 AC 70 ms
9,672 KB
testcase_26 AC 65 ms
9,312 KB
testcase_27 AC 65 ms
9,352 KB
testcase_28 AC 64 ms
9,416 KB
testcase_29 AC 64 ms
9,384 KB
testcase_30 AC 62 ms
9,352 KB
testcase_31 AC 51 ms
8,576 KB
testcase_32 AC 63 ms
9,624 KB
testcase_33 AC 56 ms
9,128 KB
testcase_34 AC 39 ms
7,364 KB
testcase_35 AC 27 ms
5,924 KB
testcase_36 AC 41 ms
8,656 KB
testcase_37 AC 8 ms
4,376 KB
testcase_38 AC 45 ms
9,128 KB
testcase_39 AC 13 ms
4,628 KB
testcase_40 AC 34 ms
7,884 KB
testcase_41 AC 38 ms
8,392 KB
testcase_42 AC 47 ms
9,392 KB
testcase_43 AC 43 ms
8,620 KB
testcase_44 AC 17 ms
5,236 KB
testcase_45 AC 37 ms
8,344 KB
testcase_46 AC 16 ms
5,068 KB
testcase_47 AC 51 ms
9,292 KB
testcase_48 AC 37 ms
7,464 KB
testcase_49 AC 55 ms
9,680 KB
testcase_50 AC 25 ms
6,132 KB
testcase_51 AC 52 ms
8,644 KB
testcase_52 AC 62 ms
9,616 KB
testcase_53 AC 16 ms
4,604 KB
testcase_54 AC 29 ms
6,296 KB
testcase_55 AC 61 ms
9,444 KB
testcase_56 AC 21 ms
5,256 KB
testcase_57 AC 40 ms
7,312 KB
testcase_58 AC 9 ms
4,376 KB
testcase_59 AC 21 ms
5,192 KB
testcase_60 AC 59 ms
9,132 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 1 ms
4,380 KB
testcase_63 AC 7 ms
4,380 KB
testcase_64 AC 3 ms
4,380 KB
testcase_65 AC 1 ms
4,380 KB
testcase_66 AC 2 ms
4,384 KB
testcase_67 AC 3 ms
4,376 KB
testcase_68 AC 4 ms
4,384 KB
testcase_69 AC 2 ms
4,380 KB
testcase_70 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

/**
 * @brief https://tkmst201.github.io/Library/DataStructure/UnionFind.hpp
 */
struct UnionFind {
public:
	using size_type = std::size_t;
	
private:
	size_type n;
	std::vector<int> dat;
	
public:
	UnionFind(size_type n) : n(n), dat(n, -1) {}
	
	size_type size(size_type x) {
		assert(x < n);
		return -dat[find(x)];
	}
	
	size_type find(size_type x) {
		assert(x < n);
		if (dat[x] < 0) return x;
		return dat[x] = find(dat[x]);
	}
	
	void unite(size_type x, size_type y) {
		assert(x < n);
		assert(y < n);
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (dat[x] < dat[y]) std::swap(x, y);
		dat[x] += dat[y];
		dat[y] = x;
	}
	
	bool issame(size_type x, size_type y) {
		assert(x < n);
		assert(y < n);
		return find(x) == find(y);
	}
};

int main() {
	int N, M, S, T;
	cin >> N >> M >> S >> T; --S; --T;
	vector<int> P(N);
	REP(i, N) scanf("%d", &P[i]);
	vector<vector<int>> g(N);
	REP(i, M){
		int a, b;
		scanf("%d %d", &a, &b);
		--a; --b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	vector<int> ord(N);
	iota(ALL(ord), 0);
	sort(ALL(ord), [&](int i, int j) { return P[i] > P[j]; });
	int cur = P[S], ans = 0;
	UnionFind uf(N);
	for (int i : ord) {
		for (int v : g[i]) if (P[i] <= P[v]) uf.unite(i, v);
		if (uf.issame(S, i) && chmin(cur, P[i])) ++ans;
	}
	cout << ans << endl;
}
0