結果

問題 No.92 逃走経路
ユーザー RonlynesRonlynes
提出日時 2017-08-22 17:32:53
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,827 bytes
コンパイル時間 845 ms
コンパイル使用メモリ 76,228 KB
実行使用メモリ 238,176 KB
最終ジャッジ日時 2024-04-23 04:45:41
合計ジャッジ時間 13,154 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

struct edge{
    int to, from, cost;
};
bool comp(const edge& e1, const edge& e2){
    if(e1.cost < e2.cost){
        return true;
    }else{
        return false;
    }
}
int main(void){
    int n, m, k, d[1001];
    vector<edge> e;

    cin >> n >> m >> k;
    
    for(int i=0; i<m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        edge e1, e2;

        e1.from = a;
        e1.to = b;
        e1.cost = c;
        
        e2.from = b;
        e2.to = a;
        e2.cost = c;
        
        e.push_back(e1);
        e.push_back(e2);
    }
    sort(e.begin(), e.end(), comp);
    for(int i=0; i<k; i++){
        cin >> d[i];
    }
    vector<int> to, tmp;
    set<int> s;
    for(int j=0; j<k; j++){
        for(int i=0; i<e.size(); i++){
            if(e[i].cost == d[j]){
                if(j != 0){
                    for(int l=0; l<to.size(); l++){
                        if(j == k-1){
                            if(e[i].from == to[l]){
                                s.insert(e[i].to);
                            }
                        }else{
                            if(e[i].from == to[l]){
                                tmp.push_back(e[i].to);
                            }
                        }
                    }
                }else{
                    tmp.push_back(e[i].to);
                }
            }
        }
        to.clear();
        for(int l=0;l<tmp.size(); l++){
            to.push_back(tmp[l]);
        }
        tmp.clear();
    }
    cout << s.size() << endl;
    set<int>::iterator ite;
    for(ite = s.begin(); ite!= s.end(); ite++){
        cout << *ite;
        if(ite != s.end()){
            cout << " ";
        }
    }
    cout << endl;
    return 0;
}
0