QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#152587 | #5672. Connectivity Problem | ftt_fan_club# | AC ✓ | 1ms | 3652kb | C++23 | 7.8kb | 2023-08-28 13:02:32 | 2023-08-28 13:02:33 |
Judging History
answer
/*
* @Author: cmk666
* @Created time: 2023-08-28 13:01:32
* @Last Modified time: 2023-08-28 13:02:17
*/
#pragma GCC optimize("Ofast", "unroll-loops")
#include<bits/stdc++.h>
#ifdef LOCAL
#include"debug.h"
#else
#define D(...) ((void)0)
#endif
using namespace std; using ll = long long;
#define For(i, j, k) for ( int i = (j) ; i <= (k) ; i++ )
#define Fol(i, j, k) for ( int i = (j) ; i >= (k) ; i-- )
namespace FastIO
{
// ------------------------------
// #define IN_HAS_NEG
// #define OUT_HAS_NEG
// #define CHK_EOF
// #define DISABLE_MMAP
// ------------------------------
#if __cplusplus < 201400
#error Please use C++14 or higher.
#endif
#if __cplusplus > 201700
#define INLINE_V inline
#else
#define INLINE_V
#endif
#if ( defined(LOCAL) || defined(_WIN32) ) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifndef DISABLE_MMAP
#include<sys/mman.h>
#endif
#ifdef LOCAL
inline char gc() { return getchar(); }
inline void pc(char c) { putchar(c); }
#else
#ifdef DISABLE_MMAP
INLINE_V constexpr int _READ_SIZE = 1 << 18;
INLINE_V static char _read_buffer[_READ_SIZE], *_read_ptr = nullptr, *_read_ptr_end = nullptr;
inline char gc()
{
if ( __builtin_expect(_read_ptr == _read_ptr_end, false) )
{
_read_ptr = _read_buffer;
_read_ptr_end = _read_buffer + fread(_read_buffer, 1, _READ_SIZE, stdin);
#ifdef CHK_EOF
if ( __builtin_expect(_read_ptr == _read_ptr_end, false) ) return EOF;
#endif
}
return *_read_ptr++;
}
#else
INLINE_V static const char *_read_ptr = (const char *)mmap(nullptr, INT_MAX, 1, 2, 0, 0);
inline char gc() { return *_read_ptr++; }
#endif
INLINE_V constexpr int _WRITE_SIZE = 1 << 18;
INLINE_V static char _write_buffer[_WRITE_SIZE], *_write_ptr = _write_buffer;
inline void pc(char c)
{
*_write_ptr++ = c;
if ( __builtin_expect(_write_buffer + _WRITE_SIZE == _write_ptr, false) )
{
fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout);
_write_ptr = _write_buffer;
}
}
INLINE_V struct _auto_flush
{
inline ~_auto_flush() { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); }
} _auto_flush;
#endif
#ifdef CHK_EOF
inline constexpr bool _isdigit(char c) { return ( c & 16 ) && c != EOF; }
inline constexpr bool _isgraph(char c) { return c > 32 && c != EOF; }
#else
inline constexpr bool _isdigit(char c) { return c & 16; }
inline constexpr bool _isgraph(char c) { return c > 32; }
#endif
template < class T >
INLINE_V constexpr bool _is_integer = numeric_limits < T >::is_integer;
template < class T >
INLINE_V constexpr bool _is_signed = numeric_limits < T >::is_signed;
template < class T >
INLINE_V constexpr bool _is_unsigned = _is_integer < T > && !_is_signed < T >;
template <> INLINE_V constexpr bool _is_integer < __int128 > = true;
template <> INLINE_V constexpr bool _is_integer < __uint128_t > = true;
template <> INLINE_V constexpr bool _is_signed < __int128 > = true;
template <> INLINE_V constexpr bool _is_unsigned < __uint128_t > = true;
#undef INLINE_V
inline void read(char &c) { do c = gc(); while ( !_isgraph(c) ); }
inline void read_cstr(char *s)
{
char c = gc(); while ( !_isgraph(c) ) c = gc();
while ( _isgraph(c) ) *s++ = c, c = gc();
*s = 0;
}
inline void read(string &s)
{
char c = gc(); s.clear(); while ( !_isgraph(c) ) c = gc();
while ( _isgraph(c) ) s.push_back(c), c = gc();
}
#ifdef IN_HAS_NEG
template < class T, enable_if_t < _is_signed < T >, int > = 0 >
inline void read(T &x)
{
char c = gc(); bool f = true; x = 0;
while ( !_isdigit(c) ) { if ( c == 45 ) f = false; c = gc(); }
if ( f ) while ( _isdigit(c) ) x = x * 10 + ( c & 15 ), c = gc();
else while ( _isdigit(c) ) x = x * 10 - ( c & 15 ), c = gc();
}
template < class T, enable_if_t < _is_unsigned < T >, int > = 0 >
#else
template < class T, enable_if_t < _is_integer < T >, int > = 0 >
#endif
inline void read(T &x)
{
char c = gc(); while ( !_isdigit(c) ) c = gc();
x = 0; while ( _isdigit(c) ) x = x * 10 + ( c & 15 ), c = gc();
}
inline void write(char c) { pc(c); }
inline void write_cstr(const char *s) { while ( *s ) pc(*s++); }
inline void write(const string &s) { for ( char c : s ) pc(c); }
#ifdef OUT_HAS_NEG
template < class T, enable_if_t < _is_signed < T >, int > = 0 >
inline void write(T x)
{
char buffer[numeric_limits < T >::digits10 + 1]; int digits = 0;
if ( x >= 0 ) do buffer[digits++] = ( x % 10 ) | 48, x /= 10; while ( x );
else { pc(45); do buffer[digits++] = -( x % 10 ) | 48, x /= 10; while ( x ); }
while ( digits ) pc(buffer[--digits]);
}
template < class T, enable_if_t < _is_unsigned < T >, int > = 0 >
#else
template < class T, enable_if_t < _is_integer < T >, int > = 0 >
#endif
inline void write(T x)
{
char buffer[numeric_limits < T >::digits10 + 1]; int digits = 0;
do buffer[digits++] = ( x % 10 ) | 48, x /= 10; while ( x );
while ( digits ) pc(buffer[--digits]);
}
template < int N > struct _tuple_io_helper
{
template < class ...T >
static inline void _read(tuple < T... > &x)
{ _tuple_io_helper < N - 1 >::_read(x), read(get < N - 1 > (x)); }
template < class ...T >
static inline void _write(const tuple < T... > &x)
{ _tuple_io_helper < N - 1 >::_write(x), pc(32), write(get < N - 1 > (x)); }
};
template <> struct _tuple_io_helper < 1 >
{
template < class ...T >
static inline void _read(tuple < T... > &x) { read(get < 0 > (x)); }
template < class ...T >
static inline void _write(const tuple < T... > &x) { write(get < 0 > (x)); }
};
template < class ...T >
inline void read(tuple < T... > &x) { _tuple_io_helper < sizeof...(T) >::_read(x); }
template < class ...T >
inline void write(const tuple < T... > &x) { _tuple_io_helper < sizeof...(T) >::_write(x); }
template < class T1, class T2 >
inline void read(pair < T1, T2 > &x) { read(x.first), read(x.second); }
template < class T1, class T2 >
inline void write(const pair < T1, T2 > &x) { write(x.first), pc(32), write(x.second); }
template < class T1, class ...T2 >
inline void read(T1 &x, T2 &...y) { read(x), read(y...); }
template < class ...T >
inline void read_cstr(char *x, T *...y) { read_cstr(x), read_cstr(y...); }
template < class T1, class ...T2 >
inline void write(const T1 &x, const T2 &...y) { write(x), write(y...); }
template < class ...T >
inline void write_cstr(const char *x, const T *...y) { write_cstr(x), write_cstr(y...); }
template < class T >
inline void print(const T &x) { write(x); }
inline void print_cstr(const char *x) { write_cstr(x); }
template < class T1, class ...T2 >
inline void print(const T1 &x, const T2 &...y) { print(x), pc(32), print(y...); }
template < class ...T >
inline void print_cstr(const char *x, const T *...y) { print_cstr(x), print_cstr(y...); }
inline void println() { pc(10); }
inline void println_cstr() { pc(10); }
template < class ...T >
inline void println(const T &...x) { print(x...), pc(10); }
template < class ...T >
inline void println_cstr(const T *...x) { print_cstr(x...), pc(10); }
}
using namespace FastIO;
namespace DSU
{
int fa[1009], sz[1009];
inline void init(int x) { For(i, 1, x) fa[i] = i, sz[i] = 1; }
inline int fat(int x) { return x == fa[x] ? x : fa[x] = fat(fa[x]); }
inline bool issame(int x, int y) { return fat(x) == fat(y); }
inline void union_(int x, int y)
{
if ( ( x = fat(x) ) == ( y = fat(y) ) ) return;
if ( sz[x] > sz[y] ) sz[x] += sz[y], fa[y] = x;
else sz[y] += sz[x], fa[x] = y;
}
}
int n, p, q;
int main()
{
read(n), DSU::init(1001);
For(_, 1, n)
{
read(p, q), p++, q++;
if ( DSU::issame(p, q) ) println("Y"s);
else println("N"s), DSU::union_(p, q);
}
return 0;
}
// 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏
// 伊娜可爱捏 伊娜贴贴捏
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3616kb
input:
12 3 4 4 9 8 1 2 3 5 6 2 9 5 9 7 3 4 8 5 6 1 8 6 1
output:
N N N N N Y N N N Y Y Y
result:
ok 12 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 3588kb
input:
100 26 39 2 21 4 17 2 16 12 19 27 0 8 43 10 12 6 29 5 9 19 32 13 47 13 36 3 6 13 18 9 40 11 40 29 16 7 24 10 35 19 41 6 24 28 21 26 35 23 47 2 30 19 17 10 6 22 6 15 25 19 11 2 8 11 25 14 23 27 1 1 16 16 0 23 34 2 25 10 17 3 35 23 37 13 0 22 7 27 29 15 13 10 5 18 40 28 46 19 0 23 40 4 46 19 3 20 39 1...
output:
N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N Y N Y Y Y N N Y Y Y Y Y N Y Y Y Y N Y Y Y Y Y Y Y N N N Y N N Y Y Y Y Y Y Y Y Y N Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y
result:
ok 100 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
200 29 19 6 28 16 17 9 11 20 25 18 41 9 17 4 3 12 24 4 30 22 2 10 39 1 20 10 23 10 11 10 0 29 37 12 22 7 46 4 1 6 28 6 39 23 10 3 11 11 22 14 31 14 24 8 39 7 45 28 20 3 2 0 6 28 19 27 42 7 10 18 10 12 11 27 14 11 23 15 23 9 11 4 28 22 33 6 15 1 15 12 32 12 47 25 2 13 29 8 30 27 2 23 22 16 38 13 9 10...
output:
N N N N N N N N N N N N N N N N N N N N Y N Y N N N N N N Y Y Y N N N N Y N Y N Y Y N Y Y N N Y N Y Y Y N Y Y Y N Y Y N Y Y Y Y Y Y N Y Y N Y Y Y N Y Y Y N Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y N Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y N Y Y Y ...
result:
ok 200 lines
Test #4:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
1000 4 11 21 24 9 47 22 2 22 35 8 22 24 13 5 17 15 30 10 3 6 8 24 9 29 19 17 7 21 46 13 1 6 31 15 2 14 27 1 34 17 2 7 33 23 37 26 12 3 20 1 18 26 39 12 39 15 22 7 41 3 0 23 26 13 18 15 20 14 16 3 35 21 9 10 12 27 43 25 38 8 21 29 37 23 6 21 47 21 13 0 23 22 17 8 7 14 49 4 37 27 8 10 45 18 2 6 45 23 ...
output:
N N N N N N N N N N N N N N N N N N N N N N N N N N N Y Y N N N Y N N Y Y N N N N N Y Y Y Y Y Y N N N N Y Y Y Y N Y N Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y N Y Y Y Y Y Y N Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y N Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y N Y Y N Y Y Y Y Y Y Y Y Y Y Y Y Y Y N Y Y Y Y ...
result:
ok 1000 lines
Test #5:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
3000 123 31 78 180 42 82 91 164 28 25 142 91 148 102 149 93 101 46 32 4 42 180 13 41 7 85 108 75 59 20 56 14 38 103 109 126 0 138 104 108 108 50 47 152 36 156 59 87 135 111 10 87 78 72 103 177 0 85 81 62 24 67 79 158 46 83 41 140 35 147 127 118 68 138 119 19 9 166 143 142 39 153 119 66 52 160 112 19...
output:
N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N Y N N N N N N N N N N N N N N N N Y N N N N N N N N N N N N N Y N Y N Y N N N N N N N N N Y N N N N N Y N N Y ...
result:
ok 3000 lines
Test #6:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
5000 149 83 70 47 5 128 22 146 149 8 9 43 69 1 129 126 119 8 60 161 112 124 78 190 77 20 137 8 149 61 63 100 132 48 9 98 96 84 0 20 74 40 27 23 1 67 27 95 41 64 134 7 54 44 14 57 26 10 106 11 136 193 111 76 25 60 39 69 43 154 146 114 38 79 51 83 78 3 88 166 69 186 85 32 11 59 94 116 124 52 97 43 84 ...
output:
N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N Y N N N N N N N N N N N N N N N N N N N N N Y N Y N N Y N N N N N N Y N N N N N N N N N N N N Y N N Y N Y N N Y Y N N N Y Y ...
result:
ok 5000 lines
Test #7:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
10000 510 915 206 189 588 690 871 253 802 171 200 257 875 77 699 781 440 52 653 286 648 388 343 442 302 425 344 481 898 14 497 76 417 93 787 381 401 151 491 951 248 76 192 712 616 21 554 708 51 543 671 27 432 275 430 318 230 989 405 990 419 249 143 62 247 349 455 202 614 947 672 608 39 445 413 445 3...
output:
N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N ...
result:
ok 10000 lines