結果

問題 No.1382 Travel in Mitaru city
ユーザー tkmst201tkmst201
提出日時 2021-02-10 12:45:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,894 bytes
コンパイル時間 2,814 ms
コンパイル使用メモリ 208,360 KB
実行使用メモリ 10,488 KB
最終ジャッジ日時 2023-09-22 06:34:35
合計ジャッジ時間 12,508 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 24 ms
4,544 KB
testcase_08 WA -
testcase_09 AC 32 ms
5,040 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 85 ms
9,448 KB
testcase_28 AC 85 ms
9,392 KB
testcase_29 AC 85 ms
9,448 KB
testcase_30 AC 80 ms
9,452 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 42 ms
8,844 KB
testcase_37 AC 8 ms
4,376 KB
testcase_38 AC 47 ms
9,400 KB
testcase_39 AC 14 ms
4,640 KB
testcase_40 AC 35 ms
7,924 KB
testcase_41 AC 40 ms
8,460 KB
testcase_42 AC 48 ms
9,448 KB
testcase_43 AC 41 ms
8,720 KB
testcase_44 AC 18 ms
5,220 KB
testcase_45 AC 38 ms
8,148 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 40 ms
7,748 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 AC 3 ms
4,380 KB
testcase_62 AC 2 ms
4,376 KB
testcase_63 AC 8 ms
4,376 KB
testcase_64 AC 3 ms
4,380 KB
testcase_65 AC 2 ms
4,376 KB
testcase_66 AC 3 ms
4,380 KB
testcase_67 AC 3 ms
4,380 KB
testcase_68 AC 3 ms
4,380 KB
testcase_69 AC 2 ms
4,376 KB
testcase_70 AC 5 ms
4,376 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]) uf.unite(i, v);
		if (uf.issame(S, i) && chmin(cur, P[i])) ++ans;
	}
	cout << ans << endl;
}
0