結果

問題 No.1382 Travel in Mitaru city
ユーザー tnakao0123tnakao0123
提出日時 2021-02-08 11:21:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,263 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 99,268 KB
実行使用メモリ 6,456 KB
最終ジャッジ日時 2023-09-18 17:32:39
合計ジャッジ時間 6,252 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 17 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 23 ms
4,376 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 54 ms
6,456 KB
testcase_28 AC 52 ms
6,308 KB
testcase_29 AC 52 ms
6,448 KB
testcase_30 AC 45 ms
6,192 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 34 ms
5,816 KB
testcase_37 AC 7 ms
4,380 KB
testcase_38 AC 37 ms
6,068 KB
testcase_39 AC 10 ms
4,380 KB
testcase_40 AC 28 ms
5,652 KB
testcase_41 AC 35 ms
5,664 KB
testcase_42 AC 42 ms
6,112 KB
testcase_43 AC 36 ms
5,852 KB
testcase_44 AC 16 ms
4,380 KB
testcase_45 AC 33 ms
5,496 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 37 ms
5,168 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 2 ms
4,380 KB
testcase_62 AC 2 ms
4,380 KB
testcase_63 AC 7 ms
4,376 KB
testcase_64 AC 3 ms
4,376 KB
testcase_65 AC 2 ms
4,380 KB
testcase_66 AC 3 ms
4,380 KB
testcase_67 AC 2 ms
4,376 KB
testcase_68 AC 3 ms
4,380 KB
testcase_69 AC 2 ms
4,376 KB
testcase_70 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1382.cc:  No.1382 Travel in Mitaru city - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef pair<int,int> pii;

struct UFT {
  int links[MAX_N], ranks[MAX_N], sizes[MAX_N];
  UFT() {}

  void init(int n) {
    for (int i = 0; i < n; i++) links[i] = i, ranks[i] = sizes[i] = 1;
  }

  int root(int i) {
    int i0 = i;
    while (links[i0] != i0) i0 = links[i0];
    return (links[i] = i0);
  }

  int rank(int i) { return ranks[root(i)]; }
  int size(int i) { return sizes[root(i)]; }
  bool same(int i, int j) { return root(i) == root(j); }

  int merge(int i0, int i1) {
    int r0 = root(i0), r1 = root(i1), mr;
    if (r0 == r1) return r0;
    if (ranks[r0] == ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      ranks[r0]++;
      mr = r0;
    }
    else if (ranks[r0] > ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      mr = r0;
    }
    else {
      links[r0] = r1;
      sizes[r1] += sizes[r0];
      mr = r1;
    }
    return mr;
  }
};

/* global variables */

int ps[MAX_N], ups[MAX_N];
UFT uft;
pii qs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m, st, gl;
  scanf("%d%d%d%d", &n, &m, &st, &gl);
  st--, gl--;

  for (int i = 0; i < n; i++)
    scanf("%d", ps + i), ups[i] = ps[i];
  sort(ups, ups + n);
  int k = unique(ups, ups + n) - ups;

  uft.init(n);

  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    uft.merge(a, b);
  }

  for (int i = 0; i < n; i++) {
    int j = lower_bound(ups, ups + k, ps[i]) - ups;
    qs[i] = pii(j, i);
  }
  sort(qs, qs + n);

  int rt = uft.root(st);
  int c = 0;
  for (int i = n - 1, w = -1; i >= 0; i--) {
    int q = qs[i].first, u = qs[i].second;
    if (uft.root(u) == rt) {
      if (w < 0) {
	if (u == st) w = q;
      }
      else {
	if (w > q) w = q, c++;
      }
    }
  }

  printf("%d\n", c);
  return 0;
}
0