結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 68 ms
11,136 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 29 ms
7,680 KB
testcase_08 WA -
testcase_09 AC 11 ms
5,376 KB
testcase_10 AC 48 ms
10,368 KB
testcase_11 AC 33 ms
8,064 KB
testcase_12 AC 20 ms
5,504 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 37 ms
6,528 KB
testcase_19 WA -
testcase_20 AC 27 ms
6,528 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 18 ms
5,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 14 ms
5,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 42 ms
8,576 KB
testcase_33 WA -
testcase_34 AC 36 ms
6,912 KB
testcase_35 WA -
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 WA -
testcase_42 AC 39 ms
8,064 KB
testcase_43 WA -
testcase_44 AC 26 ms
6,400 KB
testcase_45 WA -
testcase_46 AC 3 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>
#include <limits>

int main()
{
    /* input */
    int N, M;
    int X, Y;
    int p[200000], q[200000];
    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 );
    }
    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]);
    }

    /*
    std::vector<std::vector<std::vector<int>>> grid(2001,std::vector<std::vector<int>>(2001,std::vector<int>(100)));
    for ( int i=0; i<N; i++ ) {
        grid[p[i] + 1000][q[i] + 1000].push_back(i+1);
    }
    for ( int i=0; i<grid.size(); i++ ) {
        for ( int j=0; j<grid[i].size(); j++ ) {
            for ( int k=0; k<grid[i][j].size(); k++ ) {
                for ( int l=k+1; l<grid[i][j].size(); l++ ) {
                    list_lines[grid[i][j][k]-1].push_back(grid[i][j][l]);
                    list_lines[grid[i][j][l]-1].push_back(grid[i][j][k]);
                }
            }
        }
    }
    */

    /* process */
    double cost[200000];
    double maxcost = std::numeric_limits<double>::infinity();
    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);
            }
            if ( next == Y ) break;
        }

    }

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

    return 0;
}
0