結果
| 問題 | No.2319 Friends+ |
| コンテスト | |
| ユーザー |
👑 amentorimaru
|
| 提出日時 | 2023-03-14 21:17:22 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.89.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,221 bytes |
| 記録 | |
| コンパイル時間 | 2,305 ms |
| コンパイル使用メモリ | 111,344 KB |
| 最終ジャッジ日時 | 2025-02-11 11:20:21 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In instantiation of 'decltype(auto) read_tuple(size_t) [with Ts = {long long int, long long int}; size_t = long unsigned int]':
main.cpp:38:35: required from here
main.cpp:27:24: error: 'std::tuple<std::vector<long long int, std::allocator<long long int> >, std::vector<long long int, std::allocator<long long int> > > ts' has incomplete type
27 | tuple<vector<Ts>...> ts;
| ^~
ソースコード
#include<iostream>
#include<algorithm>
#include<vector>
#include <iterator>
#include <math.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i=(a); i<(b);i++)
#define REP(i, n) for(ll i=0; i<(n);i++)
#define INC(a) for(auto& v:a)v++;
#define DEC(a) for(auto& v:a)v--;
template<typename T = ll>
vector<T> read(size_t n) {
vector<T> ts(n);
for (size_t i = 0; i < n; i++) cin >> ts[i];
return ts;
}
template<typename TV, const ll N> void read_tuple_impl(TV&) {}
template<typename TV, const ll N, typename Head, typename... Tail>
void read_tuple_impl(TV& ts) {
get<N>(ts).emplace_back(*(istream_iterator<Head>(cin)));
read_tuple_impl<TV, N + 1, Tail...>(ts);
}
template<typename... Ts> decltype(auto) read_tuple(size_t n) {
tuple<vector<Ts>...> ts;
for (size_t i = 0; i < n; i++) read_tuple_impl<decltype(ts), 0, Ts...>(ts);
return ts;
}
int main() {
ll N, M;
cin >> N >> M;
auto P = read(N);
DEC(P);
auto [A, B] = read_tuple<ll, ll>(M);
DEC(A);
DEC(B);
vector<ll> C(N);
REP(i, M) {
C[A[i]]++;
C[B[i]]++;
}
vector<vector<ll>> few(N), many(N);
ll sqm = sqrt(M * 2);
REP(i, M) {
if (C[B[i]] < sqm)
few[A[i]].push_back(B[i]);
else
many[A[i]].push_back(B[i]);
if (C[A[i]] < sqm)
few[B[i]].push_back(A[i]);
else
many[B[i]].push_back(A[i]);
}
vector<vector<ll>> fewC(N);
REP(i, N) {
if (C[i] < sqm)
continue;
fewC[i].resize(N);
for (auto& v : few[i])
fewC[i][P[v]]++;
}
ll Q;
cin >> Q;
auto findFriend = [&](ll X, ll Y) {
if (P[X] == P[Y]) {
return false;
}
for (auto& v : many[X]) {
if (P[v] == P[Y])
return true;
}
if (C[X] < sqm) {
for (auto& v : few[X]) {
if (P[v] == P[Y])
return true;
}
return false;
}
else {
return fewC[X][P[Y]] > 0;
}
};
while (Q--) {
ll X, Y;
cin >> X >> Y;
X--; Y--;
if (findFriend(X, Y)) {
cout << "Yes\n";
if (C[X] < sqm) {
for (auto& v : many[X]) {
fewC[v][P[X]]--;
fewC[v][P[Y]]++;
}
}
P[X] = P[Y];
}
else {
cout << "No\n";
}
}
return 0;
}
amentorimaru