結果

問題 No.92 逃走経路
ユーザー RonlynesRonlynes
提出日時 2017-08-22 17:36:23
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,859 bytes
コンパイル時間 759 ms
コンパイル使用メモリ 75,872 KB
実行使用メモリ 234,992 KB
最終ジャッジ日時 2024-04-23 04:45:56
合計ジャッジ時間 13,080 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |     scanf("%d %d %d",&n,&m,&k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |         scanf("%d %d %d", &a, &b, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:41:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |         scanf("%d", &d[i]);
      |         ~~~~~^~~~~~~~~~~~~

ソースコード

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;

    scanf("%d %d %d",&n,&m,&k);
    
    for(int i=0; i<m; i++){
        int a, b, c;
        scanf("%d %d %d", &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++){
        scanf("%d", &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();
    }
    printf("%ld\n", s.size());
    set<int>::iterator ite;
    for(ite = s.begin(); ite!= s.end(); ite++){
        printf("%d",*ite);
        if(ite != s.end()){
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}
0