Submission #10122374


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#pragma region template

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;

#define F first
#define S second

#define reps(i, k, n) for (int i = (k), i##_len = (n); i < i##_len; ++i)
#define rep(i, n) reps(i, 0, n)
#define all(o) (o).begin(), (o).end()
#define sz(a) ((int)(a).size())
#define debug(x) cerr << x << " (L:" << __LINE__ << ")" << '\n';
#define bit(n) (1LL << (n))

const ll MOD = 1000000007;
const string YES = "Yes";
const string NO = "No";

const ll MAX = (ll)0x3f0000003f000000;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
          dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

template <class T>
void print(T& x) {
    cout << x << '\n';
}

struct setup_main {
    setup_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(15);
    }
} setup_main_;

#pragma endregion

ll ans = 0;

vl g(1, 0);

ll root(ll i) {
    if (g[i] == i) return i;
    return (g[i] = root(g[i]));
}
bool eqroot(ll a, ll b) {
    return ((root(a)) == (root(b)));
}
void connect(ll a, ll b) {
    if (not(eqroot(a, b))) {
        g[a] = b;
    }
}


void solve(long long N, long long Q, std::vector<long long> P,
           std::vector<long long> A, std::vector<long long> B) {
    g.resize(N);
    rep(i, N) g[i] = i;

    rep(i, Q) {
        if (P[i] == 0) connect(A[i], B[i]);
        else {
            if (eqroot(A[i], B[i])) cout << YES << endl;
            else
                cout << NO << endl;
        }
    }
}

signed main() {
    long long N;
    scanf("%lld", &N);
    long long Q;
    scanf("%lld", &Q);
    std::vector<long long> P(Q);
    std::vector<long long> A(Q);
    std::vector<long long> B(Q);
    for (int i = 0; i < Q; i++) {
        scanf("%lld", &P[i]);
        scanf("%lld", &A[i]);
        scanf("%lld", &B[i]);
    }
    solve(N, Q, std::move(P), std::move(A), std::move(B));

    return 0;
}

Submission Info

Submission Time
Task B - Union Find
User srtubaki
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2002 Byte
Status AC
Exec Time 360 ms
Memory 8064 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:81:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &N);
                      ^
./Main.cpp:83:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &Q);
                      ^
./Main.cpp:88:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &P[i]);
                             ^
./Main.cpp:89:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &A[i]);
                             ^
./Main.cpp:90:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &B[i]);
               ...

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 1
AC × 19
Set Name Test Cases
Sample 00_sample_01.txt
All 00_sample_01.txt, subtask_01_01.txt, subtask_01_02.txt, subtask_01_03.txt, subtask_01_04.txt, subtask_01_05.txt, subtask_01_06.txt, subtask_01_07.txt, subtask_01_08.txt, subtask_01_09.txt, subtask_01_10.txt, subtask_01_11.txt, subtask_01_12.txt, subtask_01_13.txt, subtask_01_14.txt, subtask_01_15.txt, subtask_01_16.txt, subtask_01_17.txt, subtask_01_18.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 256 KB
subtask_01_01.txt AC 207 ms 3584 KB
subtask_01_02.txt AC 2 ms 1024 KB
subtask_01_03.txt AC 329 ms 5760 KB
subtask_01_04.txt AC 348 ms 6272 KB
subtask_01_05.txt AC 19 ms 640 KB
subtask_01_06.txt AC 18 ms 1408 KB
subtask_01_07.txt AC 333 ms 5504 KB
subtask_01_08.txt AC 343 ms 6272 KB
subtask_01_09.txt AC 1 ms 256 KB
subtask_01_10.txt AC 2 ms 1024 KB
subtask_01_11.txt AC 333 ms 5632 KB
subtask_01_12.txt AC 356 ms 8064 KB
subtask_01_13.txt AC 269 ms 4480 KB
subtask_01_14.txt AC 2 ms 1024 KB
subtask_01_15.txt AC 333 ms 5504 KB
subtask_01_16.txt AC 360 ms 6272 KB
subtask_01_17.txt AC 209 ms 6016 KB
subtask_01_18.txt AC 206 ms 6016 KB