提出 #26928018
ソースコード 拡げる
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
int main() {
int64_t N, Q;
std::cin >> N >> Q;
std::vector<std::tuple<int64_t, int64_t, int64_t>> query(Q);
for (int64_t i = 0; i < Q; i++) {
int64_t t;
std::cin >> t;
if (t == 1) {
int64_t x = 0;
int64_t y = 0;
std::cin >> x >> y;
query.at(i) = std::make_tuple(t, x - 1, y - 1);
} else if (t == 2) {
int64_t x = 0;
int64_t y = 0;
std::cin >> x >> y;
query.at(i) = std::make_tuple(t, x - 1, y - 1);
} else if (t == 3) {
int64_t x = 0;
std::cin >> x;
query.at(i) = std::make_tuple(t, x - 1, -1);
}
}
std::vector<std::vector<int64_t>> connection(N, std::vector<int64_t>(3, -1));
for (int64_t i = 0; i < N; i++) {
connection.at(i).at(0) = i;
}
for (auto q : query) {
int64_t t = std::get<0>(q);
int64_t x = std::get<1>(q);
int64_t y = std::get<2>(q);
if (t == 1) {
connection.at(x).at(2) = y;
connection.at(y).at(0) = connection.at(x).at(0);
connection.at(y).at(1) = x;
int64_t z = connection.at(y).at(2);
while (z != -1) {
connection.at(z).at(0) = connection.at(x).at(0);
z = connection.at(z).at(2);
}
} else if (t == 2) {
connection.at(x).at(2) = -1;
connection.at(y).at(1) = -1;
connection.at(y).at(0) = y;
int64_t z = connection.at(y).at(2);
while (z != -1) {
connection.at(z).at(0) = y;
z = connection.at(z).at(2);
}
} else if (t == 3) {
int64_t z = x;
z = connection.at(z).at(0);
std::vector<int64_t> connected;
while (z != -1) {
connected.push_back(z + 1);
z = connection.at(z).at(2);
}
std::cout << connected.size() << " ";
for (size_t i = 0; i < connected.size(); i++) {
if (i) std::cout << " ";
std::cout << connected.at(i);
}
std::cout << std::endl;
}
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - Play Train |
| ユーザ | fjnkt98 |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 0 |
| コード長 | 2084 Byte |
| 結果 | TLE |
| 実行時間 | 2206 ms |
| メモリ | 14704 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 0 / 400 | ||||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example0.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, example0.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 000.txt | TLE | 2206 ms | 10964 KiB |
| 001.txt | TLE | 2206 ms | 11188 KiB |
| 002.txt | TLE | 2206 ms | 10960 KiB |
| 003.txt | TLE | 2206 ms | 11192 KiB |
| 004.txt | TLE | 2206 ms | 11192 KiB |
| 005.txt | AC | 83 ms | 12100 KiB |
| 006.txt | AC | 83 ms | 12040 KiB |
| 007.txt | AC | 66 ms | 5604 KiB |
| 008.txt | AC | 64 ms | 5548 KiB |
| 009.txt | AC | 62 ms | 5384 KiB |
| 010.txt | AC | 67 ms | 5604 KiB |
| 011.txt | AC | 66 ms | 5456 KiB |
| 012.txt | AC | 60 ms | 5444 KiB |
| 013.txt | AC | 82 ms | 6876 KiB |
| 014.txt | AC | 83 ms | 7304 KiB |
| 015.txt | AC | 83 ms | 7348 KiB |
| 016.txt | AC | 88 ms | 9212 KiB |
| 017.txt | AC | 91 ms | 10936 KiB |
| 018.txt | AC | 86 ms | 11056 KiB |
| 019.txt | AC | 89 ms | 10996 KiB |
| 020.txt | AC | 88 ms | 11096 KiB |
| 021.txt | AC | 88 ms | 11100 KiB |
| 022.txt | AC | 275 ms | 14704 KiB |
| 023.txt | AC | 276 ms | 14692 KiB |
| example0.txt | AC | 9 ms | 3524 KiB |