結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー tactac
提出日時 2020-05-29 21:54:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 3,227 bytes
コンパイル時間 2,105 ms
コンパイル使用メモリ 209,624 KB
実行使用メモリ 24,540 KB
最終ジャッジ日時 2024-04-23 21:52:35
合計ジャッジ時間 7,308 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 90 ms
13,312 KB
testcase_03 AC 148 ms
24,416 KB
testcase_04 AC 148 ms
24,328 KB
testcase_05 AC 110 ms
24,540 KB
testcase_06 AC 108 ms
24,416 KB
testcase_07 AC 27 ms
8,420 KB
testcase_08 AC 95 ms
22,400 KB
testcase_09 AC 10 ms
5,376 KB
testcase_10 AC 43 ms
11,776 KB
testcase_11 AC 29 ms
9,160 KB
testcase_12 AC 43 ms
8,152 KB
testcase_13 AC 119 ms
15,500 KB
testcase_14 AC 125 ms
17,112 KB
testcase_15 AC 152 ms
20,948 KB
testcase_16 AC 86 ms
12,484 KB
testcase_17 AC 166 ms
20,104 KB
testcase_18 AC 63 ms
9,780 KB
testcase_19 AC 147 ms
19,388 KB
testcase_20 AC 38 ms
7,936 KB
testcase_21 AC 82 ms
12,044 KB
testcase_22 AC 142 ms
17,892 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 41 ms
7,828 KB
testcase_26 AC 80 ms
13,332 KB
testcase_27 AC 92 ms
13,300 KB
testcase_28 AC 154 ms
20,508 KB
testcase_29 AC 25 ms
6,064 KB
testcase_30 AC 154 ms
21,112 KB
testcase_31 AC 97 ms
15,968 KB
testcase_32 AC 62 ms
11,836 KB
testcase_33 AC 143 ms
20,588 KB
testcase_34 AC 62 ms
9,868 KB
testcase_35 AC 160 ms
20,188 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 195 ms
22,912 KB
testcase_42 AC 49 ms
9,448 KB
testcase_43 AC 90 ms
13,824 KB
testcase_44 AC 29 ms
7,276 KB
testcase_45 AC 84 ms
13,552 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(11);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n, m;
  cin >> n >> m;
  int x, y;
  cin >> x >> y;
  x--; y--;

  vector<int> p(n), q(n);
  rep(i, n) cin >> p[i] >> q[i];

  using pid = pair<int, double>;
  vector<vector<pid> > G(n);
  auto d = [&](int a, int b) {
    return sqrt((p[a] - p[b]) * (p[a] - p[b]) + (q[a] - q[b]) * (q[a] - q[b]));
  };
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].eb(b, d(a, b));
    G[b].eb(a, d(a, b));
  }

  auto dijkstra = [&](int s) {
    using pdi = pair<double, int>;
    vector<pdi> d(n, pdi(INF, 0)); // 最短距離, その本数
    vector<int> vis(n);
    priority_queue<pdi, vector<pdi>, greater<pdi> > q;

    d[s] = pdi(0, 1);
    q.push(pdi(0, s));

    while (!q.empty()) {
      pdi p = q.top();
      q.pop();
      int v = p.S;

      if (vis[v]) continue;
      vis[v] = 1;

      for (pid np : G[v]) {
        int nv;
        double cost;
        tie(nv, cost) = np;

        pdi tmp = pdi(d[v].F + cost, d[v].S);
        if (d[nv].F != tmp.F) {
          if (chmin(d[nv], tmp)) {

          }
        }
        else d[nv] = pdi(d[nv].F, (d[nv].S + d[v].S) % mod); // 最短距離の本数増やす
        q.push(pli(d[nv].F, nv));
      }
    }
    return d;
  };
  auto di = dijkstra(x);
  cout << di[y].F << endl;
}
0