답안 #1091412

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091412 2024-09-20T19:35:41 Z andrei_iorgulescu Joker (BOI20_joker) C++14
25 / 100
53 ms 9040 KB
#include <bits/stdc++.h>

using namespace std;

int n, m, q;
int u[200005], v[200005];
int rmin[200005];

pair<int, int> t[200005];
int sz[200005];
bool bad = false;

pair<int, int> par(int x)
{
    int s1 = 0;
    while (t[x].first != x)
    {
        s1 += t[x].second;
        x = t[x].first;
    }
    return make_pair(x, s1);
}

void join(int x, int y)
{
    pair<int,int> p1 = par(x);
    pair<int,int> p2 = par(y);
    if (p1.first != p2.first)
    {
        if (sz[p1.first] < sz[p2.first])
            swap(p1, p2);
        sz[p1.first] += sz[p2.first];
        t[p2.first] = make_pair(p1.first, (1 + p1.second + p2.second));
    }
    else
    {
        if (p1.second % 2 == p2.second % 2)
        {
            bad = true;
        }
    }
}

/*
4 4 1
2 3
2 1
1 3
3 1
1 4
*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> m >> q;
    for (int i = 1; i <= m; i++)
        cin >> u[i] >> v[i];
    for (int i = 1; i <= n; i++)
        t[i] = {i, 0}, sz[i] = 1;
    rmin[1] = 1;
    for (int i = m; i >= 1; i--)
    {
        join(u[i], v[i]);
        if (bad)
        {
            rmin[1] = i;
            break;
        }
    }
    //cout << rmin[1] << endl;
    for (int i = 1; i <= q; i++)
    {
        int x, y;
        cin >> x >> y;
        if (y < rmin[x])
            cout << "YES\n";
        else
            cout << "NO\n";
    }
    return 0;
}

///wtfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

/**
deci teoretic daca bag elementele de la 1 la N, apoi fac two pointers-ul, o sa cam am queue-like undoing pe DSU, pe care tin si ceva de bipartit
**/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 43 ms 7508 KB Output is correct
4 Correct 44 ms 8272 KB Output is correct
5 Correct 44 ms 8792 KB Output is correct
6 Correct 42 ms 7556 KB Output is correct
7 Correct 42 ms 7424 KB Output is correct
8 Correct 40 ms 6740 KB Output is correct
9 Correct 41 ms 7504 KB Output is correct
10 Correct 43 ms 8484 KB Output is correct
11 Correct 46 ms 7752 KB Output is correct
12 Correct 44 ms 8788 KB Output is correct
13 Correct 45 ms 6736 KB Output is correct
14 Correct 45 ms 7332 KB Output is correct
15 Correct 53 ms 8276 KB Output is correct
16 Correct 44 ms 9040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -