結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー Koki ShinjoKoki Shinjo
提出日時 2020-05-29 22:12:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,678 bytes
コンパイル時間 627 ms
コンパイル使用メモリ 70,784 KB
実行使用メモリ 18,560 KB
最終ジャッジ日時 2024-04-23 22:49:02
合計ジャッジ時間 4,069 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 18 ms
5,504 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 34 ms
6,656 KB
testcase_19 WA -
testcase_20 AC 24 ms
6,656 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 16 ms
5,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 12 ms
5,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 34 ms
8,832 KB
testcase_33 WA -
testcase_34 AC 32 ms
7,040 KB
testcase_35 WA -
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

int main()
{
    /* input */
    int N, M;
    int X, Y;
    int p[200000], q[200000];
    int maxp = 0, maxq = 0;
    int P[200000], Q[100000];
    scanf( " %d %d", &N, &M );
    scanf( " %d %d", &X, &Y );
    std::vector<std::vector<int>> list_lines(N);
    for ( int i=0; i<N; i++ ) {
        scanf( " %d %d", p+i, q+i );
        if ( maxp < std::abs(p[i]) ) maxp = std::abs(p[i]);
        if ( maxq < std::abs(q[i]) ) maxq = std::abs(q[i]);
    }
    for ( int i=0; i<M; i++ ) {
        scanf( " %d %d", P+i, Q+i );
        list_lines[P[i]-1].push_back(Q[i]);
        list_lines[Q[i]-1].push_back(P[i]);
    }

    /* process */
    double cost[200000];
    double maxcost = ( maxp + maxq ) * 2.0;
    for ( int i=0; i<N; i++ ) {
        cost[i] = maxcost;
    }
    std::queue<int> q_graph;
    q_graph.push(X);
    cost[X-1] = 0;
    int current, next;
    double distance;
    while ( not q_graph.empty() ) {
        current = q_graph.front();
        q_graph.pop();
        for ( int i=0; i<list_lines[current-1].size(); i++ ) {
            next = list_lines[current-1][i];
            distance = std::sqrt(
                        ( p[current-1] - p[next-1] ) * ( p[current-1] - p[next-1] )
                      + ( q[current-1] - q[next-1] ) * ( q[current-1] - q[next-1] )
                    );
            if ( cost[next-1] > cost[current-1] + distance ) {
                cost[next-1] = cost[current-1] + distance;
                q_graph.push(next);
            }
        }

    }

    /* output */
    printf( "%.8lf\n", cost[Y-1] );

    return 0;
}
0