QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#528315 | #7324. Eulerian Orientation | xhgua | TL | 0ms | 43196kb | C++14 | 2.4kb | 2024-08-23 12:40:09 | 2024-08-23 12:40:09 |
Judging History
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;
memset(head, -1, sizeof(head));
memset(vis, 0, sizeof(vis));
memset(s, 0, sizeof(s));
memset(val, 0, sizeof(val));
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 43196kb
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
Time Limit Exceeded
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 ...