답안 #925810

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925810 2024-02-12T09:13:01 Z vjudge1 Joker (BOI20_joker) C++17
39 / 100
142 ms 23240 KB
//Bismillahir-Rahmanir-Rahim

#include <bits/stdc++.h>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,popcnt,avx,avx2")

#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long>
#define pld pair <long double, long double>
#define ll long long
#define ld long double
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define sz(s) (int)s.size()
#define skip continue
#define bpop(x) (ll)__builtin_popcountll(x)

using namespace std;

const int N = 2e5 + 7;
const int M = 1e3 + 7;
const int maxA = 2e6 + 7;
const int inf = 1e9 + 7;
const ll INF = 2e18 + 7;
const int MOD = 1e9 + 7;
const ld eps = 1e-9;

pii dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//#define int long long

pii E[N];
vector <int> g[N];
int n, m, q, dist[N];
vector <pii> qs;
bool bfs(int st) {
    queue <int> q;
    q.push(st), dist[st] = 0;
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (auto to : g[v]) {
            if (dist[to] == -1)dist[to] = 1 - dist[v], q.push(to);
            else if (dist[v] == dist[to]) {
                //cout << v << ':' << dist[v] << ' ' << to << ':' << dist[to] << '\n';
                return 1;
            }
        }
    }
    return 0;
}
void subtask12() {
    for (auto p : qs) {
        int l, r;
        tie(l, r) = p;
        for (int i = 1;i <= n;i++)g[i].clear(), dist[i] = -1;
        for (int i = 1;i <= m;i++) {
            if (l <= i && i <= r)skip;
            g[E[i].x].pb(E[i].y), g[E[i].y].pb(E[i].x);
            //cout << E[i].x << ' ' << E[i].y << '\n';
        }
        bool ans = 0;
        for (int i = 1;i <= n;i++) {
            if (dist[i] == -1)ans |= bfs(i);
        }
        cout << (ans ? "YES" : "NO") << '\n';
    }
    exit(0);
}
int color[N];
vector <int> vs[N];
int get(int x) {
    return (x == color[x] ? x : color[x] = get(color[x]));
}
void subtask3() {
    for (int i = 1;i <= n;i++)dist[i] = -1, color[i] = i, vs[i] = {i};
    int pos = 0;
    for (int i = m;i >= 1;i--) {
        int x = E[i].x, y = E[i].y;
        int Lx = get(x), Ly = get(y);
        if (sz(vs[Lx]) > sz(vs[Ly]))swap(x, y), swap(Lx, Ly);
        if (dist[x] == -1 && dist[y] == -1)dist[x] = 0, dist[y] = 1, color[x] = y, vs[y].pb(x), vs[x].clear();
        else if (dist[x] == -1)dist[x] = 1 - dist[y], color[x] = Ly, vs[Ly].pb(x), vs[x].clear();
        else {
            if (Lx != Ly) {
                color[Lx] = Ly;
                //cout << Lx << "->" << Ly << ":\n";
                bool change = (dist[x] == dist[y]);
                for (auto v : vs[Lx])vs[Ly].pb(v), color[v] = Ly, dist[v] ^= change;// cout << v << ' ';
                //cout << '\n';
                vs[Lx].clear();
            }
            else if (dist[x] == dist[y]) {
                pos = i;
                break;
            }
        }
        /*cout << i << ":\n";
        for (int i = 1;i <= n;i++) {
            if (dist[i] != -1)cout << i << ':' << dist[i] << ' ' << color[i] << '\n';
        }
        cout << '\n';*/
    }
    //cout << pos << ":\n";
    for (auto p : qs) {
        int r = p.y;
        if (pos > r)cout << "YES\n";
        else cout << "NO\n";
    }
    exit(0);
}
void solve() {
    cin >> n >> m >> q;
    for (int i = 1;i <= m;i++) {
        int x, y;
        cin >> x >> y;
        E[i] = {x, y};
    }
    bool solve_for_pref = 1;
    for (int i = 0;i < q;i++) {
        int l, r;
        cin >> l >> r;
        qs.pb({l, r});
        solve_for_pref &= (l == 1);
    }
    if (solve_for_pref)subtask3();
    if (n <= 2000 && m <= 2000 && q <= 2000)subtask12();
}
signed main() {
    //srand(time(NULL));
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    //freopen("tests.in", "r", stdin);
    //freopen("milkorder.out", "w", stdout);
    int test = 1;
    //cin >> test;
    for (int t = 1;t <= test;t++) {
        //cout << "Case " << t << ": ";
        solve();
    }
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13116 KB Output is correct
2 Correct 3 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12704 KB Output is correct
5 Correct 2 ms 12892 KB Output is correct
6 Correct 2 ms 12892 KB Output is correct
7 Correct 4 ms 12888 KB Output is correct
8 Correct 4 ms 12892 KB Output is correct
9 Correct 3 ms 12888 KB Output is correct
10 Correct 3 ms 12892 KB Output is correct
11 Correct 4 ms 12912 KB Output is correct
12 Correct 3 ms 12892 KB Output is correct
13 Correct 4 ms 12892 KB Output is correct
14 Correct 3 ms 12728 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 3 ms 12892 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 3 ms 12888 KB Output is correct
20 Correct 3 ms 12888 KB Output is correct
21 Correct 3 ms 12888 KB Output is correct
22 Correct 4 ms 12892 KB Output is correct
23 Correct 3 ms 12892 KB Output is correct
24 Correct 3 ms 12892 KB Output is correct
25 Correct 4 ms 12892 KB Output is correct
26 Correct 3 ms 12892 KB Output is correct
27 Correct 3 ms 12892 KB Output is correct
28 Correct 4 ms 12888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13116 KB Output is correct
2 Correct 3 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12704 KB Output is correct
5 Correct 2 ms 12892 KB Output is correct
6 Correct 2 ms 12892 KB Output is correct
7 Correct 4 ms 12888 KB Output is correct
8 Correct 4 ms 12892 KB Output is correct
9 Correct 3 ms 12888 KB Output is correct
10 Correct 3 ms 12892 KB Output is correct
11 Correct 4 ms 12912 KB Output is correct
12 Correct 3 ms 12892 KB Output is correct
13 Correct 4 ms 12892 KB Output is correct
14 Correct 3 ms 12728 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 3 ms 12892 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 3 ms 12888 KB Output is correct
20 Correct 3 ms 12888 KB Output is correct
21 Correct 3 ms 12888 KB Output is correct
22 Correct 4 ms 12892 KB Output is correct
23 Correct 3 ms 12892 KB Output is correct
24 Correct 3 ms 12892 KB Output is correct
25 Correct 4 ms 12892 KB Output is correct
26 Correct 3 ms 12892 KB Output is correct
27 Correct 3 ms 12892 KB Output is correct
28 Correct 4 ms 12888 KB Output is correct
29 Correct 115 ms 12888 KB Output is correct
30 Correct 135 ms 12888 KB Output is correct
31 Correct 109 ms 12888 KB Output is correct
32 Correct 69 ms 12988 KB Output is correct
33 Correct 52 ms 12992 KB Output is correct
34 Correct 142 ms 12892 KB Output is correct
35 Correct 141 ms 12892 KB Output is correct
36 Correct 45 ms 12892 KB Output is correct
37 Correct 91 ms 12892 KB Output is correct
38 Correct 63 ms 13024 KB Output is correct
39 Correct 106 ms 13144 KB Output is correct
40 Correct 66 ms 12996 KB Output is correct
41 Correct 64 ms 12992 KB Output is correct
42 Correct 63 ms 13004 KB Output is correct
43 Correct 49 ms 12992 KB Output is correct
44 Correct 55 ms 12992 KB Output is correct
45 Correct 92 ms 12888 KB Output is correct
46 Correct 115 ms 13000 KB Output is correct
47 Correct 54 ms 12988 KB Output is correct
48 Correct 71 ms 12984 KB Output is correct
49 Correct 93 ms 13000 KB Output is correct
50 Correct 132 ms 13004 KB Output is correct
51 Correct 50 ms 12888 KB Output is correct
52 Correct 73 ms 13012 KB Output is correct
53 Correct 96 ms 12892 KB Output is correct
54 Correct 140 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13116 KB Output is correct
2 Correct 3 ms 12892 KB Output is correct
3 Correct 58 ms 19364 KB Output is correct
4 Correct 78 ms 23240 KB Output is correct
5 Correct 62 ms 20736 KB Output is correct
6 Correct 58 ms 19148 KB Output is correct
7 Correct 62 ms 20004 KB Output is correct
8 Correct 57 ms 17860 KB Output is correct
9 Correct 61 ms 19460 KB Output is correct
10 Correct 69 ms 22220 KB Output is correct
11 Correct 59 ms 18892 KB Output is correct
12 Correct 66 ms 21412 KB Output is correct
13 Correct 59 ms 16004 KB Output is correct
14 Correct 67 ms 17704 KB Output is correct
15 Correct 63 ms 20936 KB Output is correct
16 Correct 73 ms 21956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13116 KB Output is correct
2 Correct 3 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12704 KB Output is correct
5 Correct 2 ms 12892 KB Output is correct
6 Correct 2 ms 12892 KB Output is correct
7 Correct 4 ms 12888 KB Output is correct
8 Correct 4 ms 12892 KB Output is correct
9 Correct 3 ms 12888 KB Output is correct
10 Correct 3 ms 12892 KB Output is correct
11 Correct 4 ms 12912 KB Output is correct
12 Correct 3 ms 12892 KB Output is correct
13 Correct 4 ms 12892 KB Output is correct
14 Correct 3 ms 12728 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 3 ms 12892 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 3 ms 12888 KB Output is correct
20 Correct 3 ms 12888 KB Output is correct
21 Correct 3 ms 12888 KB Output is correct
22 Correct 4 ms 12892 KB Output is correct
23 Correct 3 ms 12892 KB Output is correct
24 Correct 3 ms 12892 KB Output is correct
25 Correct 4 ms 12892 KB Output is correct
26 Correct 3 ms 12892 KB Output is correct
27 Correct 3 ms 12892 KB Output is correct
28 Correct 4 ms 12888 KB Output is correct
29 Correct 58 ms 19364 KB Output is correct
30 Correct 78 ms 23240 KB Output is correct
31 Correct 62 ms 20736 KB Output is correct
32 Correct 58 ms 19148 KB Output is correct
33 Correct 62 ms 20004 KB Output is correct
34 Correct 57 ms 17860 KB Output is correct
35 Correct 61 ms 19460 KB Output is correct
36 Correct 69 ms 22220 KB Output is correct
37 Correct 59 ms 18892 KB Output is correct
38 Correct 66 ms 21412 KB Output is correct
39 Correct 59 ms 16004 KB Output is correct
40 Correct 67 ms 17704 KB Output is correct
41 Correct 63 ms 20936 KB Output is correct
42 Correct 73 ms 21956 KB Output is correct
43 Incorrect 49 ms 14948 KB Output isn't correct
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13116 KB Output is correct
2 Correct 3 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12704 KB Output is correct
5 Correct 2 ms 12892 KB Output is correct
6 Correct 2 ms 12892 KB Output is correct
7 Correct 4 ms 12888 KB Output is correct
8 Correct 4 ms 12892 KB Output is correct
9 Correct 3 ms 12888 KB Output is correct
10 Correct 3 ms 12892 KB Output is correct
11 Correct 4 ms 12912 KB Output is correct
12 Correct 3 ms 12892 KB Output is correct
13 Correct 4 ms 12892 KB Output is correct
14 Correct 3 ms 12728 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 3 ms 12892 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 3 ms 12888 KB Output is correct
20 Correct 3 ms 12888 KB Output is correct
21 Correct 3 ms 12888 KB Output is correct
22 Correct 4 ms 12892 KB Output is correct
23 Correct 3 ms 12892 KB Output is correct
24 Correct 3 ms 12892 KB Output is correct
25 Correct 4 ms 12892 KB Output is correct
26 Correct 3 ms 12892 KB Output is correct
27 Correct 3 ms 12892 KB Output is correct
28 Correct 4 ms 12888 KB Output is correct
29 Correct 115 ms 12888 KB Output is correct
30 Correct 135 ms 12888 KB Output is correct
31 Correct 109 ms 12888 KB Output is correct
32 Correct 69 ms 12988 KB Output is correct
33 Correct 52 ms 12992 KB Output is correct
34 Correct 142 ms 12892 KB Output is correct
35 Correct 141 ms 12892 KB Output is correct
36 Correct 45 ms 12892 KB Output is correct
37 Correct 91 ms 12892 KB Output is correct
38 Correct 63 ms 13024 KB Output is correct
39 Correct 106 ms 13144 KB Output is correct
40 Correct 66 ms 12996 KB Output is correct
41 Correct 64 ms 12992 KB Output is correct
42 Correct 63 ms 13004 KB Output is correct
43 Correct 49 ms 12992 KB Output is correct
44 Correct 55 ms 12992 KB Output is correct
45 Correct 92 ms 12888 KB Output is correct
46 Correct 115 ms 13000 KB Output is correct
47 Correct 54 ms 12988 KB Output is correct
48 Correct 71 ms 12984 KB Output is correct
49 Correct 93 ms 13000 KB Output is correct
50 Correct 132 ms 13004 KB Output is correct
51 Correct 50 ms 12888 KB Output is correct
52 Correct 73 ms 13012 KB Output is correct
53 Correct 96 ms 12892 KB Output is correct
54 Correct 140 ms 12892 KB Output is correct
55 Incorrect 26 ms 12892 KB Output isn't correct
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 13116 KB Output is correct
2 Correct 3 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 12704 KB Output is correct
5 Correct 2 ms 12892 KB Output is correct
6 Correct 2 ms 12892 KB Output is correct
7 Correct 4 ms 12888 KB Output is correct
8 Correct 4 ms 12892 KB Output is correct
9 Correct 3 ms 12888 KB Output is correct
10 Correct 3 ms 12892 KB Output is correct
11 Correct 4 ms 12912 KB Output is correct
12 Correct 3 ms 12892 KB Output is correct
13 Correct 4 ms 12892 KB Output is correct
14 Correct 3 ms 12728 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 3 ms 12892 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 3 ms 12888 KB Output is correct
20 Correct 3 ms 12888 KB Output is correct
21 Correct 3 ms 12888 KB Output is correct
22 Correct 4 ms 12892 KB Output is correct
23 Correct 3 ms 12892 KB Output is correct
24 Correct 3 ms 12892 KB Output is correct
25 Correct 4 ms 12892 KB Output is correct
26 Correct 3 ms 12892 KB Output is correct
27 Correct 3 ms 12892 KB Output is correct
28 Correct 4 ms 12888 KB Output is correct
29 Correct 115 ms 12888 KB Output is correct
30 Correct 135 ms 12888 KB Output is correct
31 Correct 109 ms 12888 KB Output is correct
32 Correct 69 ms 12988 KB Output is correct
33 Correct 52 ms 12992 KB Output is correct
34 Correct 142 ms 12892 KB Output is correct
35 Correct 141 ms 12892 KB Output is correct
36 Correct 45 ms 12892 KB Output is correct
37 Correct 91 ms 12892 KB Output is correct
38 Correct 63 ms 13024 KB Output is correct
39 Correct 106 ms 13144 KB Output is correct
40 Correct 66 ms 12996 KB Output is correct
41 Correct 64 ms 12992 KB Output is correct
42 Correct 63 ms 13004 KB Output is correct
43 Correct 49 ms 12992 KB Output is correct
44 Correct 55 ms 12992 KB Output is correct
45 Correct 92 ms 12888 KB Output is correct
46 Correct 115 ms 13000 KB Output is correct
47 Correct 54 ms 12988 KB Output is correct
48 Correct 71 ms 12984 KB Output is correct
49 Correct 93 ms 13000 KB Output is correct
50 Correct 132 ms 13004 KB Output is correct
51 Correct 50 ms 12888 KB Output is correct
52 Correct 73 ms 13012 KB Output is correct
53 Correct 96 ms 12892 KB Output is correct
54 Correct 140 ms 12892 KB Output is correct
55 Correct 58 ms 19364 KB Output is correct
56 Correct 78 ms 23240 KB Output is correct
57 Correct 62 ms 20736 KB Output is correct
58 Correct 58 ms 19148 KB Output is correct
59 Correct 62 ms 20004 KB Output is correct
60 Correct 57 ms 17860 KB Output is correct
61 Correct 61 ms 19460 KB Output is correct
62 Correct 69 ms 22220 KB Output is correct
63 Correct 59 ms 18892 KB Output is correct
64 Correct 66 ms 21412 KB Output is correct
65 Correct 59 ms 16004 KB Output is correct
66 Correct 67 ms 17704 KB Output is correct
67 Correct 63 ms 20936 KB Output is correct
68 Correct 73 ms 21956 KB Output is correct
69 Incorrect 49 ms 14948 KB Output isn't correct
70 Halted 0 ms 0 KB -