結果

問題 No.1382 Travel in Mitaru city
ユーザー SSRSSSRS
提出日時 2021-02-07 20:53:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 247 ms / 2,000 ms
コード長 1,395 bytes
コンパイル時間 3,370 ms
コンパイル使用メモリ 184,460 KB
実行使用メモリ 25,904 KB
最終ジャッジ日時 2023-09-17 19:41:24
合計ジャッジ時間 14,776 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 60 ms
6,216 KB
testcase_07 AC 48 ms
5,960 KB
testcase_08 AC 28 ms
5,392 KB
testcase_09 AC 65 ms
6,260 KB
testcase_10 AC 63 ms
6,216 KB
testcase_11 AC 135 ms
16,488 KB
testcase_12 AC 143 ms
16,508 KB
testcase_13 AC 145 ms
16,692 KB
testcase_14 AC 133 ms
16,408 KB
testcase_15 AC 138 ms
16,432 KB
testcase_16 AC 239 ms
25,904 KB
testcase_17 AC 240 ms
25,248 KB
testcase_18 AC 244 ms
25,320 KB
testcase_19 AC 237 ms
25,448 KB
testcase_20 AC 232 ms
25,508 KB
testcase_21 AC 233 ms
25,448 KB
testcase_22 AC 237 ms
25,644 KB
testcase_23 AC 243 ms
25,508 KB
testcase_24 AC 247 ms
25,376 KB
testcase_25 AC 237 ms
25,624 KB
testcase_26 AC 131 ms
10,000 KB
testcase_27 AC 135 ms
10,120 KB
testcase_28 AC 130 ms
10,204 KB
testcase_29 AC 130 ms
9,768 KB
testcase_30 AC 127 ms
10,124 KB
testcase_31 AC 106 ms
9,244 KB
testcase_32 AC 130 ms
10,252 KB
testcase_33 AC 119 ms
9,656 KB
testcase_34 AC 81 ms
7,752 KB
testcase_35 AC 54 ms
6,328 KB
testcase_36 AC 89 ms
9,244 KB
testcase_37 AC 15 ms
4,380 KB
testcase_38 AC 99 ms
9,556 KB
testcase_39 AC 26 ms
4,640 KB
testcase_40 AC 75 ms
8,056 KB
testcase_41 AC 83 ms
8,540 KB
testcase_42 AC 101 ms
9,772 KB
testcase_43 AC 87 ms
8,848 KB
testcase_44 AC 36 ms
5,536 KB
testcase_45 AC 79 ms
8,268 KB
testcase_46 AC 30 ms
5,224 KB
testcase_47 AC 108 ms
9,664 KB
testcase_48 AC 75 ms
7,940 KB
testcase_49 AC 115 ms
10,156 KB
testcase_50 AC 52 ms
6,512 KB
testcase_51 AC 183 ms
22,324 KB
testcase_52 AC 225 ms
25,640 KB
testcase_53 AC 46 ms
8,324 KB
testcase_54 AC 91 ms
13,452 KB
testcase_55 AC 214 ms
24,672 KB
testcase_56 AC 64 ms
11,184 KB
testcase_57 AC 135 ms
17,788 KB
testcase_58 AC 20 ms
5,984 KB
testcase_59 AC 65 ms
10,220 KB
testcase_60 AC 206 ms
24,216 KB
testcase_61 AC 4 ms
4,380 KB
testcase_62 AC 1 ms
4,380 KB
testcase_63 AC 14 ms
4,380 KB
testcase_64 AC 5 ms
4,380 KB
testcase_65 AC 2 ms
4,384 KB
testcase_66 AC 3 ms
4,380 KB
testcase_67 AC 4 ms
4,376 KB
testcase_68 AC 6 ms
4,376 KB
testcase_69 AC 3 ms
4,380 KB
testcase_70 AC 7 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
struct unionfind{
	vector<int> p;
	unionfind(int N){
		p = vector<int>(N, -1);
	}
	int root(int x){
		if (p[x] < 0){
			return x;
		} else {
			p[x] = root(p[x]);
			return p[x];
		}
	}
	bool same(int x, int y){
		return root(x) == root(y);
	}
	void unite(int x, int y){
		x = root(x);
		y = root(y);
		if (x != y){
			if (p[x] < p[y]){
				swap(x, y);
			}
			p[y] += p[x];
			p[x] = y;
		}
	}
};
int main(){
  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>> E(N);
  for (int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    E[a].push_back(b);
    E[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 P : mp){
    g.push_back(P.second);
  }
  reverse(g.begin(), g.end());
  int ans = 0;
  unionfind UF(N);
  vector<bool> used(N, false);
  for (auto gg : g){
    for (int v : gg){
      used[v] = true;
      for (int w : E[v]){
        if (used[w]){
          if (!UF.same(v, w)){
            UF.unite(v, w);
          }
        }
      }
    }
    bool ok = false;
    for (int v : gg){
      if (UF.same(v, S) && p[v] < p[S]){
        ok = true;
      }
    }
    if (ok){
      ans++;
    }
  }
  cout << ans << endl;
}
0