QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#528321#7324. Eulerian OrientationxhguaWA 669ms13852kbC++142.4kb2024-08-23 12:41:032024-08-23 12:41:04

Judging History

你现在查看的是最新测评结果

  • [2024-08-23 12:41:04]
  • 评测
  • 测评结果:WA
  • 用时:669ms
  • 内存:13852kb
  • [2024-08-23 12:41:03]
  • 提交

answer

#include <bits/stdc++.h>

#define i64 long long
#define ui64 unsigned i64
#define all(x) x.begin(), x.end()
#define seg(a, l, r) a + l, a + r + 1
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)

using namespace std;

const int N = 1e6 + 5, MOD = 1e9 + 7;

mt19937_64 mt_rand(chrono::system_clock::now().time_since_epoch().count()); 

struct Edge {
    int u, v, nxt;

    Edge() {}
    Edge(int _u, int _v, int _nxt) {
        u = _u; v = _v; nxt = _nxt;
    }
} E[N << 1];

int n, m, c, tot;
int pw2[N], head[N];
ui64 s[N << 1], val[N << 1];
bool vis[N]; 

void addEdge(int u, int v) {
    E[tot] = Edge(u, v, head[u]);
    head[u] = tot++;
}

void dfs(int u, int last) {
    vis[u] = true;

    for(int i = head[u]; ~i; i = E[i].nxt) {
        int v = E[i].v;
        if(i == (last ^ 1)) continue;

        if(!vis[v]) {
            dfs(v, i);
            val[i / 2] = s[v];
            s[u] ^= s[v];
        }
        else if(val[i / 2] == 0) {
            val[i / 2] = mt_rand() + 1;
            s[u] ^= val[i / 2];
            s[v] ^= val[i / 2];
        }
    }
}

int main() {

    // freopen("fish.in", "r", stdin);
    // freopen("fish.out", "w", stdout);

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

    while (cin >> n >> m) {
        c = 0; tot = 0;
        rep(i, 0, n) head[i] = -1, vis[i] = 0;
        rep(i, 0, 2 * m) s[i] = val[i] = 0;
        rep(i, 1, m) {
            int u, v; cin >> u >> v;
            addEdge(u, v);
            addEdge(v, u);
        }

        pw2[0] = 1;
        rep(i, 1, m) pw2[i] = pw2[i - 1] * 2 % MOD;

        rep(i, 1, n) if(!vis[i]) dfs(i, 0), c++;

        int cnt = 0; // 非割边条数
        rep(i, 0, m - 1) if(val[i] > 0) cnt++;

        i64 ans = 1ll * cnt * pw2[m - n + c - 1] % MOD;

        sort(seg(val, 0, m - 1));
        for(int l = 0, r = 0; l < m; l = r + 1) {
            r = l;
            while(val[r + 1] == val[l]) r++;

            if(val[l] != 0) {
                int len = r - l + 1;
                ans = (ans + 1ll * len * (len - 1) % MOD * pw2[m - n + c - 1] % MOD) % MOD;
                ans = (ans + 1ll * len * (cnt - len) % MOD * pw2[m - n + c - 2] % MOD) % MOD;
            }
        }

        cout << ans << "\n";
    }

    return 0;
}

/*

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

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 13852kb

input:

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

output:

9
54
14

result:

ok 3 number(s): "9 54 14"

Test #2:

score: -100
Wrong Answer
time: 669ms
memory: 13852kb

input:

5 6
5 4
1 5
3 3
5 1
5 3
2 5
5 3
4 1
1 3
4 5
5 2
3 1
2 5
5 8
4 3
5 4
2 5
3 1
5 3
1 5
2 1
5 1
5 10
4 2
5 4
4 4
2 4
3 4
2 3
4 3
1 5
2 5
5 5
5 4
2 2
3 1
4 3
1 4
5 7
4 4
5 5
4 5
1 5
5 1
5 1
2 4
5 7
5 2
5 5
1 4
1 4
4 3
2 2
2 5
5 0
5 10
4 3
5 5
4 4
5 4
4 1
4 2
4 2
5 4
5 2
1 1
5 1
5 5
5 9
3 1
4 2
5 3
4 3
1 ...

output:

14
1
1
304
1472
26
120
184
0
1152
1
736
0
1
192
1
24
736
0
68
4
464
72
336
184
6
248
44
128
312
9
4
1
0
464
44
1
68
0
42
1
272
312
6
232
6
592
768
176
0
0
64
232
0
1
0
120
736
1
0
0
140
1
896
1856
1
0
1504
38
1
1248
0
232
26
1
1824
0
0
0
0
0
0
0
592
0
4
40
304
9
1472
720
0
1
0
0
0
1
0
64
768
1
24
35...

result:

wrong answer 2nd numbers differ - expected: '0', found: '1'