結果

問題 No.92 逃走経路
ユーザー kurenai3110kurenai3110
提出日時 2016-06-22 17:17:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 460 ms / 5,000 ms
コード長 1,315 bytes
コンパイル時間 830 ms
コンパイル使用メモリ 85,836 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 00:21:25
合計ジャッジ時間 2,939 ms
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
6,820 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 21 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 31 ms
6,944 KB
testcase_10 AC 275 ms
6,940 KB
testcase_11 AC 297 ms
6,944 KB
testcase_12 AC 460 ms
6,940 KB
testcase_13 AC 12 ms
6,944 KB
testcase_14 AC 25 ms
6,940 KB
testcase_15 AC 36 ms
6,944 KB
testcase_16 AC 23 ms
6,940 KB
testcase_17 AC 22 ms
6,944 KB
testcase_18 AC 11 ms
6,944 KB
testcase_19 AC 6 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

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);
	vector<long> c;
    c.resize(m);
    int a,b;
	for (int i = 0; i<m; i++) {
		cin >> a >> b >> c[i];
		h[i] = make_pair(c[i],make_pair(a,b));
	}
    sort(h.begin(),h.end());
    sort(c.begin(),c.end());

	long x;
	set<int> nr;
	for (int i = 0; i < k; i++) {
        set<int> r;
		cin >> x;
        int f = distance(c.begin(),lower_bound(c.begin(),c.end(),x));
		while (f<m&&h[f].first==x) {
			if (i == 0) {
				r.insert(h[f].second.first);
				r.insert(h[f].second.second);
			}
			else {
				int y;
				for (auto itnr = nr.begin();itnr!=nr.end();itnr++) {
					y = solve(*(itnr), h[f].second);
					if (y) {
						r.insert(y);
					}
				}
			}
            f++;
		}
        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