QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#639136#7898. I Just Want... One More...szlhc#WA 11ms14064kbC++143.3kb2024-10-13 18:03:162024-10-13 18:03:21

Judging History

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

  • [2024-10-13 18:03:21]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:14064kb
  • [2024-10-13 18:03:16]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <utility>
using namespace std;
const int N = 2e5 + 5, M = 3e5 + 5, inf = 0x3f3f3f3f;
int cas, n, m, mat[N], chg[N], non[N];
vector <int> g[N];
namespace network {
    int s, t, tot, head[N], cur[N], dep[N];
    struct edge {
        int u, v, w, nxt;
    }e[M << 1];
    inline void add_edge (int u, int v, int w) {
        e[++tot] = {u, v, w, head[u]};
        head[u] = tot;
        e[++tot] = {v, u, 0, head[v]};
        head[v] = tot;
    }
    bool bfs() {
        queue <int> q;
        for (int i = s; i <= t; i++) cur[i] = head[i], dep[i] = -1;
        dep[s] = 0;
        q.push(s);
        while (!q.empty()) {
            int u = q.front();
            q.pop();
            for (int i = head[u]; i; i = e[i].nxt) {
                int v = e[i].v, w = e[i].w;
                if (w && dep[v] == -1) {
                    dep[v] = dep[u] + 1;
                    q.push(v);
                }
            }
        }
        return ~dep[t];
    }
    int dfs (int u, int flow) {
        if (!flow || u == t) return flow;
        int res = 0;
        for (int &i = cur[u]; i; i = e[i].nxt) {
            int v = e[i].v, w = e[i].w;
            if (w && dep[v] == dep[u] + 1) {
                int add_flow = dfs(v, min(flow, w));
                flow -= add_flow, res += add_flow;
                e[i].w -= add_flow, e[i ^ 1].w += add_flow;
                if (!flow) break;
            }
        }
        if (!res) dep[u] = -1;
        return res;
    }
    int Dinic() {
        int max_flow = 0;
        while (bfs()) max_flow += dfs(s, inf);
        return max_flow;
    }
}
using namespace network;
int dfs2 (int u);
int dfs1 (int u) {
    if (~non[u]) return non[u];
    if (!mat[u]) return non[u] = 1;
    non[u] = 0;
    if (dfs2(mat[u])) return non[u] = 1;
    return 0;
}
int dfs2 (int u) {
    if (~chg[u]) return chg[u];
    chg[u] = 0;
    for (int v : g[u]) {
        if (v != mat[u] && dfs1(v)) return chg[u] = 1;
    }
    return 0;
}
map <pair<int, int>, int> mp;
int main() {
    scanf ("%d", &cas);
    while (cas--) {
        scanf ("%d%d", &n, &m);
        s = 0, t = 2 * n + 1, tot = 1;
        mp.clear();
        int num_edge = 0;
        for (int i = 1, u, v; i <= m; i++) {
            scanf ("%d%d", &u, &v);
            if (!mp[{u, v}]) {
                mp[{u, v}] = 1;
                add_edge(u, v + n, 1);
                g[u].push_back(v + n);
                g[v + n].push_back(u);
                num_edge++;
            }
        }
        for (int i = 1; i <= n; i++) {
            add_edge(s, i, 1);
            add_edge(i + n, t, 1);
        }
        Dinic();
        for (int i = 1; i <= num_edge; i++) {
            if (!e[2 * i].w) {
                mat[e[2 * i].u] = e[2 * i].v;
                mat[e[2 * i].v] = e[2 * i].u;
            }
        }
        int cnt1 = 0, cnt2 = 0;
        for (int i = 1; i <= 2 * n; i++) chg[i] = non[i] = -1;
        for (int u = 1; u <= n; u++) cnt1 += dfs1(u);
        for (int u = 1; u <= n; u++) cnt2 += dfs1(u + n);
        printf ("%lld\n", 1ll * cnt1 * cnt2);
        for (int i = s; i <= t; i++) head[i] = 0;
        for (int i = 1; i <= 2 * n; i++) mat[i] = 0, g[i].clear();
    }
    return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 10280kb

input:

3
4 3
1 2
3 2
4 3
3 3
1 3
2 2
3 1
3 2
1 2
1 2

output:

6
0
4

result:

ok 3 number(s): "6 0 4"

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 14064kb

input:

10000
5 4
2 2
3 1
5 3
1 1
1 1
1 1
1 1
1 1
2 2
2 2
1 2
1 1
1 1
1 1
1 1
1 1
1 1
2 3
2 1
1 2
1 1
5 5
1 4
2 2
3 1
1 3
1 2
2 4
2 2
2 1
1 2
1 1
5 1
5 3
3 1
2 2
1 1
1 1
3 2
3 1
2 1
5 2
1 2
2 3
5 3
1 5
4 2
1 2
4 1
1 1
2 3
1 1
2 2
2 1
4 1
1 4
3 1
1 1
1 1
1 1
2 1
2 2
3 3
1 3
2 3
2 2
3 3
1 3
3 3
1 2
3 3
2 2
1 ...

output:

6
0
0
2
0
0
0
0
6
0
16
4
0
6
9
9
9
0
9
4
0
1
1
1
0
4
16
12
3
2
16
0
2
2
20
1
0
0
0
0
16
4
4
16
4
9
0
9
0
2
3
0
9
4
9
16
20
0
0
1
12
0
1
2
0
0
1
0
0
2
2
4
0
12
1
0
0
2
1
2
2
3
0
4
1
6
0
0
0
0
9
16
2
0
1
2
0
12
2
4
0
12
1
1
9
4
6
9
9
12
3
16
15
16
9
4
9
0
1
16
9
9
1
9
16
9
12
4
9
2
0
4
0
6
0
3
0
0
0
0...

result:

wrong answer 726th numbers differ - expected: '3', found: '2'