結果

問題 No.92 逃走経路
ユーザー rullonzrullonz
提出日時 2017-10-27 23:43:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 2,572 bytes
コンパイル時間 1,736 ms
コンパイル使用メモリ 172,028 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-01 17:59:17
合計ジャッジ時間 2,545 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 5 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 5 ms
5,376 KB
testcase_16 AC 7 ms
5,376 KB
testcase_17 AC 7 ms
5,376 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct edge {int /*from**/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
//static const int INF = 2147483647;
//static const long long INf = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define itn int
#define scnaf scanf
#define reutnr return
#define scamf scanf
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
//#define int ll

const int NMAX = 114;
const int KMAX = 1145;

int n,m,k;
VE G[NMAX];
int d[KMAX];
int dp[KMAX][NMAX]; //dp[i][j]はi番目に街jを使うときの通り

void print(){
    for(int i=0;i<=k;i++){
        for(int j=0;j<n;j++){
            printf("%d ",dp[i][j]);
        }
        printf("\n");
    }
    printf("\n");
}

void print2(){
    for(int i=0;i<k;i++){
        printf("%d ",d[i]);
    }
    printf("\n\n");
}

void print3(){
    for(int i=0;i<n;i++){
        for(int j=0;j<G[i].size();j++){
            printf("%d ",G[i][j]);
        }
        printf("\n");
    }
    printf("\n");
}

signed main(){
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0;i<m;i++){
        int tmp1,tmp2,tmp3;
        scanf("%d%d%d",&tmp1,&tmp2,&tmp3);
        tmp1--;tmp2--;
        edge a,b;
        a.to=tmp2; b.to=tmp1; a.cost=b.cost=tmp3;
        G[tmp1].pb(a); G[tmp2].pb(b);
    }
    //print3();
    for(int i=0;i<k;i++){
        int tmp;
        scanf("%d",&tmp);
        d[i] = tmp;
    }
    //print2();
    for(int i=0;i<n;i++) dp[0][i] = 1;

    for(int i=0;i<k;i++){
        int dist = d[i];
        for(int j=0;j<n;j++){
            for(int k=0;k<G[j].size();k++){
                edge e = G[j][k];
                if(e.cost==dist && dp[i][j]){
                    dp[i+1][e.to] = 1;
                }
            }
        }
    }
    //print();
    int ans = 0;
    VI ans2;
    for(int i=0;i<n;i++){
        if(dp[k][i]){
            ans++;
            ans2.pb(i+1);
        }
    }
    printf("%d\n",ans);
    for(int i=0;i<ans2.size();i++){
        printf("%d ",ans2[i]);
    }
    printf("\n");
    return 0;
}
0