답안 #914317

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914317 2024-01-21T15:46:58 Z Amr Joker (BOI20_joker) C++14
0 / 100
54 ms 5244 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define S second
#define F first
#define all(x) (x).begin(),(x).end()
#define sz size()
#define Yes cout << "YES" << endl
#define No cout << "NO" << endl
#define pb(x) push_back(x);
#define endl '\n'
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N=3e5+7;
ll INF=INT_MAX,mod=1e9+7;
int TT=1;
ll power(ll x, unsigned int y)
{
    ll res = 1;
    x = x; // % mod;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1) res = (res*x)  ; // % mod;
        y = y>>1;
        x = (x*x) ; // % mod;
    }
    return res;
}
pair<ll,ll> p[N];
ll siz[N];
pair<ll,ll> get(ll x)
{
    if(p[x].F==x) return p[x];
    pair<ll,ll> hi = get(p[x].F);
    return {hi.F,hi.S^p[x].S};
}
void solve()
{

    ll n , m, q; cin >> n >> m >> q;
    for(int i = 1; i <= n; i++) siz[i] = 1,p[i] = {i,0};
    ll lst = m+1;
    for(int i = 1; i <= m; i++)
    {
        ll x, y; cin >> x >> y;
        pair<ll,ll> paix = get(x);
        pair<ll,ll> paiy = get(y);
        ll xx = paix.F, yy = paiy.F;
       // cout << xx << " " << yy << endl;
        if(paix.F!=paiy.F)
        {
            bool b = (paix.S==paiy.S);
            if(siz[xx]<siz[yy])
            {
                p[xx] = {yy,b};
                siz[yy]+=siz[xx];

            }
            else
            {
                p[yy] = {xx,b};
                siz[xx]+=siz[yy];
            }
        }
        else
        {
            if(paix.S==paiy.S&&lst==m+1) {lst = i;}
        }
    }
    while(q--)
    {
        ll l, r; cin >> l >> r;
        if(r>=lst) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}
int main(){
    //freopen("friday.in","r",stdin);
    //freopen("friday.out","w",stdout);
    fast;
    //cin >> TT;
    while(TT--)
        solve();

    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Incorrect 1 ms 2648 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Incorrect 1 ms 2648 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Incorrect 54 ms 5244 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Incorrect 1 ms 2648 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Incorrect 1 ms 2648 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Incorrect 1 ms 2648 KB Output isn't correct
4 Halted 0 ms 0 KB -