結果

問題 No.92 逃走経路
ユーザー kurenai3110kurenai3110
提出日時 2016-06-22 16:47:35
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,389 bytes
コンパイル時間 694 ms
コンパイル使用メモリ 80,612 KB
実行使用メモリ 170,912 KB
最終ジャッジ日時 2024-04-20 00:21:11
合計ジャッジ時間 7,192 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 TLE -
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 <algorithm>
#include <map>
#include <iterator>
#include <set>
using namespace std;

int solve(int n, pair<int, int> &hfs);

int main() {
	int n, m, k;
	cin >> n >> m >> k;

	vector<pair<long, pair<int, int> > > h;
    h.resize(m);
	multiset<long> c1;
    int a,b;
    long c;
	for (int i = 0; i<m; i++) {
		cin >> a >> b >> c;
        c1.insert(c);
		h[i] = make_pair(c,make_pair(a,b));
	}

	long x;
	set<int> nr;
	for (int i = 0; i < k; i++) {
        set<int> r;
		cin >> x;
        auto itc1 = c1.find(x);
        int f = distance(c1.begin(),itc1);
		int s = nr.size();
		while (1) {
            if(*(itc1)==x){
			if (i == 0) {
				r.insert(h[f].second.first);
				r.insert(h[f].second.second);
			}
			else {
				int y;
                auto itnr = nr.begin();
				for (int j = 0; j <s; j++) {
					y = solve(*(itnr), h[f].second);
					if (y) {
						r.insert(y);
					}
                    itnr++;
				}
			}
			itc1++; 
            f++;
            }else break;
		}
        nr.clear();
        nr=r;
	}
    auto itnr = nr.begin(); 
	cout << nr.size() << endl;
	for (int i=0;i<nr.size(); i++) {
		if (i) cout << " ";
		cout << *(itnr);
        itnr++;
	}
	cout << endl;

	return 0;
}

int solve(int n, pair<int, int> &hfs) {
	if (n == hfs.first) {
		return hfs.second;
	}
	else if (n == hfs.second) {
		return hfs.first;
	}
	return 0;
}
0