結果
| 問題 |
No.92 逃走経路
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2014-12-07 20:07:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 5,000 ms |
| コード長 | 1,550 bytes |
| コンパイル時間 | 769 ms |
| コンパイル使用メモリ | 70,076 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-11 16:21:41 |
| 合計ジャッジ時間 | 1,574 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:54:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
54 | scanf("%d %d %d", &n, &m, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:59:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
59 | scanf("%d %d %d", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:66:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
66 | For(i, k) scanf("%d", &ks[i]);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define For(i,x) for (int i=0; i<(int)(x); i++)
typedef vector<int> vi;
const int N = 110;
void calc(int n, const vi& ks, const set<int> adj[][N]) {
set<int> nodes;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j) continue;
if (adj[i][j].find(ks[0]) != adj[i][j].end()) {
nodes.insert(j);
}
}
}
for (int i = 1; i < ks.size(); i++) {
int cost = ks[i];
set<int> nexts;
for (std::set<int>::iterator p = nodes.begin(); p != nodes.end(); ++p) {
int node = *p;
for (int j = 1; j <= n; j++) {
if (node == j) continue;
if (adj[node][j].find(cost) != adj[node][j].end()) {
nexts.insert(j);
}
}
}
nexts.swap(nodes);
}
vi v(nodes.begin(), nodes.end());
printf("%d\n", (int)v.size());
For(i, v.size()) {
if (i > 0) printf(" ");
printf("%d", v[i]);
}
printf("\n");
}
int main() {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
std::set<int> adj[N][N];
For(i, m) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
adj[a][b].insert(c);
adj[b][a].insert(c);
}
vi ks(k);
For(i, k) scanf("%d", &ks[i]);
calc(n, ks, adj);
}
norioc