QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#618840 | #7898. I Just Want... One More... | AmiyaCast | WA | 7ms | 3604kb | C++20 | 2.5kb | 2024-10-07 10:52:47 | 2024-10-07 10:52:49 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<int, int>
const ll inf = 1145141919810;
using namespace std;
struct Dinic {
ll st, ed, n, m, cnt;
vector<ll> nxt, to, head, c, pre, cur, d;
Dinic(int _n, int _m, int _st, int _ed){//点数,边数,原点,会点。
n = _n, m = _m, st = _st, ed = _ed, cnt = 1;
nxt.resize(2 * m + 10), to.resize(2 * m + 10), c.resize(2 * m + 10);
head.resize(n + 10), pre.resize(n + 10), cur.resize(n + 10), d.resize(n + 10);
}
void Add(int x, int y, ll z) {
nxt[++cnt] = head[x], to[cnt] = y, c[cnt] = z, head[x] = cnt;
}
void add(int x, int y, ll z){
Add(x, y, z), Add(y, x, 0);
}
bool bfs() {
for(int i = 1; i <= n; ++i) d[i] = 0;
queue<ll>q;
q.push(st);
d[st] = 1;
while(q.size()) {
int x = q.front();
q.pop();
for(int i = head[x]; i; i = nxt[i]) {
int y = to[i];
if(d[y] == 0 && c[i]) {
d[y] = d[x] + 1;
q.push(y);
if(y == ed) return 1;
}
}
}
return 0;
}
ll dfs(int x, ll mf) { // mf表示剩余的流量
if(x == ed) return mf;
ll sum = 0;
for(int i = cur[x]; i; i = nxt[i]) {
cur[x] = i;
int y = to[i];
if(d[y] == d[x] + 1 && c[i]) {
ll f = dfs(y, min(c[i], mf));
c[i] -= f;
c[i ^ 1] += f;
sum += f;
mf -= f;
if(mf == 0) break;
}
}
if(sum == 0) d[x] = 0;//剪枝
return sum;//这个就是这个点的ans
}
ll dinic() {
ll flow = 0;
while(bfs()) {
cur = head;
flow += dfs(st, inf);
}
return flow;
}
};
void slv(){
int n, m;
cin >> n >> m;
Dinic d(2 * n, 3 * n + 1, 2 * n + 1, 2 * n + 2);
vector<int> v1, v2, v(2 * n + 5);
queue<int> st, ed;
for(int i = 1; i <= n; ++i) d.add(d.st, i, 1);
for(int i = 1; i <= n; ++i) d.add(i + n, d.ed, 1);
for(int i = 0; i < m; ++i){
int x, y; cin >> x >> y;
d.add(x, y + n, 1);
}
d.dinic();
st.push(d.st), ed.push(d.ed);
while(st.size()){
int x = st.front();
st.pop(), v[x] = 1;
if(x != d.st && x <= n) v1.push_back(x);
for(int i = d.head[x]; i; i = d.nxt[i]){
if(d.c[i] && !v[d.to[i]]) st.push(d.to[i]);
}
}
while(ed.size()){
int x = ed.front();
ed.pop(), v[x] = 1;
if(x != d.ed && x > n) v2.push_back(x);
for(int i = d.head[x]; i; i = d.nxt[i]){
if(d.c[i ^ 1] && !v[d.to[i]]) ed.push(d.to[i]);
}
}
cout << v1.size() * v2.size() << endl;
}
int main(){
// ios::sync_with_stdio(0), cin.tie(0);
int _ = 1;
cin >> _;
while(_--) slv();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
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: 7ms
memory: 3584kb
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 24 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 4 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 35th numbers differ - expected: '20', found: '24'