結果

問題 No.1382 Travel in Mitaru city
ユーザー Example0911Example0911
提出日時 2021-02-11 17:33:09
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,834 bytes
コンパイル時間 2,991 ms
コンパイル使用メモリ 217,684 KB
実行使用メモリ 26,904 KB
最終ジャッジ日時 2023-09-25 07:15:02
合計ジャッジ時間 13,253 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 32 ms
6,200 KB
testcase_07 AC 25 ms
6,156 KB
testcase_08 AC 18 ms
5,548 KB
testcase_09 AC 33 ms
6,656 KB
testcase_10 AC 31 ms
6,136 KB
testcase_11 AC 96 ms
17,080 KB
testcase_12 AC 89 ms
17,120 KB
testcase_13 AC 93 ms
17,192 KB
testcase_14 AC 89 ms
17,024 KB
testcase_15 AC 94 ms
17,056 KB
testcase_16 AC 172 ms
26,016 KB
testcase_17 AC 182 ms
26,256 KB
testcase_18 AC 174 ms
26,156 KB
testcase_19 AC 171 ms
26,232 KB
testcase_20 AC 172 ms
26,104 KB
testcase_21 AC 176 ms
26,064 KB
testcase_22 AC 160 ms
25,992 KB
testcase_23 AC 154 ms
26,152 KB
testcase_24 AC 175 ms
26,320 KB
testcase_25 AC 175 ms
26,040 KB
testcase_26 AC 65 ms
10,816 KB
testcase_27 AC 63 ms
10,776 KB
testcase_28 AC 65 ms
10,784 KB
testcase_29 AC 63 ms
10,980 KB
testcase_30 AC 59 ms
10,904 KB
testcase_31 AC 50 ms
9,832 KB
testcase_32 AC 63 ms
10,924 KB
testcase_33 AC 61 ms
10,604 KB
testcase_34 AC 40 ms
8,324 KB
testcase_35 AC 26 ms
6,472 KB
testcase_36 AC 38 ms
9,720 KB
testcase_37 AC 7 ms
4,380 KB
testcase_38 AC 42 ms
10,408 KB
testcase_39 AC 13 ms
5,128 KB
testcase_40 AC 33 ms
8,724 KB
testcase_41 AC 36 ms
9,400 KB
testcase_42 AC 43 ms
10,380 KB
testcase_43 AC 38 ms
9,668 KB
testcase_44 AC 17 ms
5,872 KB
testcase_45 AC 35 ms
9,020 KB
testcase_46 AC 16 ms
5,468 KB
testcase_47 AC 50 ms
10,608 KB
testcase_48 AC 36 ms
8,404 KB
testcase_49 AC 57 ms
10,976 KB
testcase_50 AC 27 ms
6,816 KB
testcase_51 AC 141 ms
22,848 KB
testcase_52 AC 167 ms
26,904 KB
testcase_53 AC 34 ms
8,632 KB
testcase_54 AC 72 ms
13,712 KB
testcase_55 AC 165 ms
25,572 KB
testcase_56 AC 42 ms
11,236 KB
testcase_57 AC 94 ms
18,240 KB
testcase_58 AC 14 ms
5,744 KB
testcase_59 AC 42 ms
10,520 KB
testcase_60 AC 148 ms
25,108 KB
testcase_61 AC 3 ms
4,376 KB
testcase_62 AC 2 ms
4,380 KB
testcase_63 AC 7 ms
4,380 KB
testcase_64 AC 3 ms
4,376 KB
testcase_65 AC 2 ms
4,380 KB
testcase_66 AC 2 ms
4,380 KB
testcase_67 AC 3 ms
4,380 KB
testcase_68 AC 4 ms
4,380 KB
testcase_69 AC 2 ms
4,380 KB
testcase_70 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = (ll)1e9 + 7;
struct UnionFind {
	vector<int>par, vsize, esize;
	UnionFind(int sz_) : par(sz_), vsize(sz_, 1), esize(sz_, 0) {
		for (int i = 0; i < sz_; i++)par[i] = i;
	}
	void init(int sz_) {
		par.resize(sz_);
		vsize.resize(sz_, 1);
		esize.resize(sz_, 0);
		for (int i = 0; i < sz_; i++)par[i] = i;
	}
	int root(int x) {
		if (par[x] == x)return x;
		else return par[x] = root(par[x]);
	}
	bool merge(int x, int y) {
		x = root(x), y = root(y);
		if (x == y) {
			esize[x]++;
			return false;
		}
		if (vsize[x] < vsize[y])swap(x, y);
		vsize[x] += vsize[y];
		esize[x] += esize[y] + 1;
		par[y] = x;
		return true;
	}
	bool issame(int x, int y) {
		return root(x) == root(y);
	}
	int vs(int x) {
		return vsize[root(x)];
	}
	int es(int x) {
		return esize[root(x)];
	}
};
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, M, S, T; cin >> N >> M >> S >> T; S--; T--;
	vector<int>p(N); for (int i = 0; i < N; i++)cin >> p[i];
	vector<vector<int>>G(N);
	for (int i = 0; i < M; i++) {
		int a, b; cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	map<int, vector<int>>mp;
	for (int i = 0; i < N; i++) {
		mp[p[i]].push_back(i);
	}
	vector<vector<int>>g;
	for (auto x : mp) {
		g.push_back(x.second);
	}
	// p_iが大きい淳に見ていく
	reverse(g.begin(), g.end());
	UnionFind uf(N);
	vector<bool>used(N);
	int ans = 0;
	for (auto x : g) {
		for (auto v : x) {
			used[v] = true;
			for (auto nv : G[v]) {
				if (used[nv]) {
					if (!uf.issame(v, nv)) {
						uf.merge(v, nv);
					}
				}
			}
		}
		bool ok = false;
		for (auto v : x) {
			if (uf.issame(v, S) && p[v] < p[S]) {
				ok = true;
			}
		}
		if (ok)ans++;
	}
	cout << ans << endl;
	return 0;
}
0