QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#930658#8729. TikvaniCyanmond41 1ms3712kbC++232.3kb2025-03-10 02:56:052025-03-10 02:56:05

Judging History

This is the latest submission verdict.

  • [2025-03-10 02:56:05]
  • Judged
  • Verdict: 41
  • Time: 1ms
  • Memory: 3712kb
  • [2025-03-10 02:56:05]
  • 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(m);
    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;
        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: 21
Accepted

Test #1:

score: 21
Accepted
time: 0ms
memory: 3584kb

input:

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

output:

32

result:

ok 1 number(s): "32"

Test #2:

score: 21
Accepted
time: 1ms
memory: 3584kb

input:

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

output:

32

result:

ok 1 number(s): "32"

Test #3:

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

input:

6 7
3 6
1 3
3 5
2 3
1 6
2 6
2 5

output:

16

result:

ok 1 number(s): "16"

Test #4:

score: 21
Accepted
time: 0ms
memory: 3584kb

input:

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

output:

32

result:

ok 1 number(s): "32"

Test #5:

score: 21
Accepted
time: 0ms
memory: 3584kb

input:

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

output:

64

result:

ok 1 number(s): "64"

Test #6:

score: 21
Accepted
time: 1ms
memory: 3584kb

input:

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

output:

32

result:

ok 1 number(s): "32"

Test #7:

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

input:

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

output:

32

result:

ok 1 number(s): "32"

Test #8:

score: 21
Accepted
time: 0ms
memory: 3584kb

input:

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

output:

64

result:

ok 1 number(s): "64"

Test #9:

score: 21
Accepted
time: 0ms
memory: 3584kb

input:

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

output:

32

result:

ok 1 number(s): "32"

Test #10:

score: 21
Accepted
time: 0ms
memory: 3584kb

input:

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

output:

32

result:

ok 1 number(s): "32"

Test #11:

score: 21
Accepted
time: 0ms
memory: 3584kb

input:

6 7
2 6
4 5
1 2
5 6
2 4
1 5
2 5

output:

16

result:

ok 1 number(s): "16"

Test #12:

score: 21
Accepted
time: 0ms
memory: 3584kb

input:

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

output:

32

result:

ok 1 number(s): "32"

Test #13:

score: 21
Accepted
time: 0ms
memory: 3584kb

input:

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

output:

32

result:

ok 1 number(s): "32"

Subtask #2:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #14:

score: 20
Accepted
time: 0ms
memory: 3584kb

input:

13 12
4 10
1 11
6 10
1 7
3 6
3 8
4 12
5 9
1 5
6 11
10 11
6 12

output:

2048

result:

ok 1 number(s): "2048"

Test #15:

score: 20
Accepted
time: 0ms
memory: 3584kb

input:

13 13
6 12
1 2
5 10
5 6
1 3
3 10
3 12
7 8
4 12
1 6
3 7
3 9
7 13

output:

4096

result:

ok 1 number(s): "4096"

Test #16:

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

input:

13 14
1 10
2 8
4 12
5 6
5 13
10 11
10 12
2 11
3 6
4 7
1 8
3 12
3 5
3 11

output:

8192

result:

ok 1 number(s): "8192"

Test #17:

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

input:

13 15
4 11
2 8
2 5
3 6
9 10
3 10
2 11
10 12
8 11
5 11
4 10
1 4
8 10
7 9
3 11

output:

8192

result:

ok 1 number(s): "8192"

Test #18:

score: 20
Accepted
time: 0ms
memory: 3584kb

input:

13 16
2 10
9 11
6 13
5 11
11 12
5 6
4 5
3 7
5 10
8 11
9 10
1 3
5 8
1 10
3 12
3 10

output:

16384

result:

ok 1 number(s): "16384"

Test #19:

score: 20
Accepted
time: 0ms
memory: 3584kb

input:

13 17
10 13
9 12
1 9
2 3
8 11
9 10
3 10
2 7
3 6
5 12
1 6
2 4
1 7
2 5
3 9
5 8
2 9

output:

16384

result:

ok 1 number(s): "16384"

Test #20:

score: 20
Accepted
time: 0ms
memory: 3584kb

input:

13 18
7 10
6 10
3 8
4 8
5 6
4 13
1 5
5 9
1 6
3 9
2 12
4 9
3 4
1 12
10 11
5 11
3 7
6 8

output:

16384

result:

ok 1 number(s): "16384"

Test #21:

score: 20
Accepted
time: 0ms
memory: 3584kb

input:

13 20
5 13
2 13
4 6
1 12
10 12
1 8
2 8
7 13
1 5
1 6
6 12
8 10
7 11
3 5
3 10
5 10
1 13
4 11
6 10
8 13

output:

4096

result:

ok 1 number(s): "4096"

Test #22:

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

input:

13 25
5 10
2 11
1 3
4 13
9 13
6 11
8 13
1 4
2 9
4 5
3 4
5 6
2 12
8 12
2 4
6 13
3 7
4 7
5 7
11 12
5 13
3 13
12 13
1 2
4 12

output:

4096

result:

ok 1 number(s): "4096"

Test #23:

score: 20
Accepted
time: 1ms
memory: 3584kb

input:

13 50
2 3
3 4
1 2
2 11
1 7
6 13
2 7
3 7
8 12
1 9
12 13
4 10
7 11
3 9
1 4
7 13
6 9
5 9
1 12
3 11
6 12
1 3
3 13
8 11
2 13
10 13
1 13
8 9
7 12
3 10
8 10
2 8
4 5
5 8
7 9
5 7
6 11
4 9
3 6
4 7
2 4
6 7
7 10
6 10
5 13
8 13
10 12
1 11
4 6
7 8

output:

4096

result:

ok 1 number(s): "4096"

Test #24:

score: 20
Accepted
time: 0ms
memory: 3584kb

input:

13 78
6 12
8 12
4 6
7 12
2 13
8 9
6 13
5 9
4 5
1 6
8 13
1 10
2 12
1 9
2 7
4 10
4 13
4 11
5 8
1 3
9 12
1 5
3 7
3 11
5 13
2 9
9 13
1 4
1 8
6 10
2 11
10 13
3 6
8 10
11 12
9 11
9 10
6 8
1 7
5 6
4 7
10 12
5 11
2 10
6 9
4 12
2 8
4 9
3 12
11 13
7 11
3 5
6 11
1 13
3 8
8 11
1 11
2 6
5 7
6 7
7 9
1 12
2 3
7 13...

output:

4096

result:

ok 1 number(s): "4096"

Subtask #3:

score: 0
Wrong Answer

Test #25:

score: 37
Accepted
time: 1ms
memory: 3584kb

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: 0
Wrong Answer
time: 0ms
memory: 3584kb

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:

487370169

result:

wrong answer 1st numbers differ - expected: '743685088', found: '487370169'

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%