QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#930656#8729. TikvaniCyanmond0 0ms3712kbC++232.3kb2025-03-10 02:53:592025-03-10 02:54:00

Judging History

This is the latest submission verdict.

  • [2025-03-10 02:54:00]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 3712kb
  • [2025-03-10 02:53:59]
  • Submitted

answer

#include <bits/stdc++.h>
#define AOTSUKI

using namespace std;
constexpr bool isMultiCase = 0;

// #include "angel/math/modint.hpp"

using ll = long long;
template <class T> constexpr int len(const T &c) {
    return int(std::ssize(c));
}
template <class T> using V = vector<T>;
template <class T> using RevPq = priority_queue<T, vector<T>, greater<T>>;
constexpr char eoln = '\n';
#define L(i, l, r) for (int i = (l); i < (r); ++i)
#define R(i, l, r) for (int i = (r) - 1; i >= (l); --i)
#define ALL(x) (x).begin(), (x).end()
#define fi first
#define se second

constexpr ll mod = 1000000007;

struct Dsu {
    int n, comps;
    V<int> data;

    Dsu(int n_) : n(n_), comps(n), data(n, -1) {}

    int find(int v) {
        if (data[v] >= 0) return data[v] = find(data[v]);
        else return v;
    }

    void unite(int a, int b) {
        a = find(a);
        b = find(b);
        if (a == b) return;
        --comps;
        if (data[a] > data[b]) swap(a, b);
        data[a] += data[b];
        data[b] = a;
    }
};

void solve() {
    int n, m; cin >> n >> m;
    V<V<int>> g(n);
    V<int> a(m), b(m);
    L(t, 0, m) {
        int u, v; cin >> u >> v; --u, --v;
        a[t] = u; b[t] = v;
        g[u].push_back(v);
    }

    V<V<bool>> reachable(n, V<bool>(n));
    L(f, 0, n) {
        queue<int> que;
        que.push(f);
        auto &used = reachable[f];
        used[f] = true;
        while (not que.empty()) {
            auto u = que.front(); que.pop();
            for (int t : g[u]) {
                if (used[t]) continue;
                used[t] = true;
                que.push(t);
            }
        }
    }

    Dsu uft(n);
    L(i, 0, m) {
        L(j, 0, m) {
            if (b[i] != b[j]) continue;
            L(f, 0, n) {
                if (reachable[f][a[i]] and reachable[f][a[j]]) {
                    uft.unite(i, j);
                }
            }
        }
    }
    int k = uft.comps;
    ll ans = 1;
    while (k--) {
        ans *= 2;
        if (ans >= mod) ans -= mod;
    }

    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    if (not isMultiCase) {
        solve();
    } else {
        int t;
        cin >> t;
        while (t--) solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3584kb

input:

6 5
3 5
2 5
1 6
4 6
2 6

output:

64

result:

wrong answer 1st numbers differ - expected: '32', found: '64'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #25:

score: 37
Accepted
time: 0ms
memory: 3712kb

input:

50 50
29 32
3 12
36 41
10 30
6 18
20 27
14 36
4 33
6 7
17 31
33 40
2 49
19 42
3 30
2 18
11 42
21 29
11 23
1 35
32 50
22 46
6 22
42 48
15 23
7 43
11 13
5 9
40 50
25 42
5 31
27 30
1 17
14 48
5 44
35 41
1 23
10 21
40 48
12 36
13 37
23 37
23 43
19 26
6 15
13 45
19 27
17 29
20 38
29 42
26 49

output:

974740338

result:

ok 1 number(s): "974740338"

Test #26:

score: 37
Accepted
time: 0ms
memory: 3712kb

input:

49 50
23 42
22 30
8 18
28 42
14 37
34 40
11 34
2 5
9 14
24 34
11 32
41 45
8 28
6 23
9 17
22 31
20 38
4 47
2 39
13 22
14 26
8 45
37 45
17 23
34 37
13 37
33 48
5 12
17 37
27 30
17 21
18 22
28 43
10 23
33 43
31 49
10 43
8 26
12 19
14 28
6 14
2 20
12 49
26 39
35 45
14 48
3 6
14 36
6 48
1 17

output:

743685088

result:

ok 1 number(s): "743685088"

Test #27:

score: 0
Wrong Answer
time: 0ms
memory: 3584kb

input:

48 50
4 39
3 43
41 47
10 34
19 36
5 17
19 35
34 38
5 30
32 47
10 41
3 44
11 29
13 37
5 47
18 33
1 45
29 45
2 13
2 38
8 36
3 34
40 45
8 20
4 21
4 31
18 43
29 32
26 38
13 29
35 48
10 36
1 9
14 23
13 34
16 27
5 18
16 36
1 6
1 36
36 44
39 43
21 39
30 42
11 18
5 11
9 37
15 30
25 45
29 40

output:

92960636

result:

wrong answer 1st numbers differ - expected: '371842544', found: '92960636'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%