QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#662804#7898. I Just Want... One More...frankly6WA 2ms5772kbC++173.2kb2024-10-21 10:41:292024-10-21 10:41:30

Judging History

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

  • [2024-10-21 10:41:30]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5772kb
  • [2024-10-21 10:41:29]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int MX=100010;
const int inf=0x3fffffff;

int Cases, N, M, S, T, siz;
int head[2*MX], cnt=1;
int dep[2*MX], cur[2*MX];
bool vis[2*MX];
int read()
{
    int r=0, f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {r=r*10+ch-'0'; ch=getchar();}
    return r*f;
}
struct edge{int nxt, to, c;}e[20*MX];
inline void ae(int u, int v, int c)
{
    e[++cnt].to=v; e[cnt].nxt=head[u]; head[u]=cnt; e[cnt].c=c;
    e[++cnt].to=u; e[cnt].nxt=head[v]; head[v]=cnt; e[cnt].c=0;
}
queue<int> q, q1, q2;
bool bfs()
{
    for(int i=1;i<=siz;i++) dep[i]=0;
    while(!q.empty()) q.pop();
    q.push(S); dep[S]=1; cur[S]=head[S];
    while(!q.empty())
    {
        int x=q.front(); q.pop();
        for(int i=head[x];i;i=e[i].nxt)
        {
            int y=e[i].to;
            if(dep[y]||!e[i].c) continue;
            dep[y]=dep[x]+1;
            cur[y]=head[y];
            if(y==T) return 1;
            q.push(y);
        }
    }
    return 0;
}
int find(int u, int lim)
{
    if(u==T) return lim;
    int res=0;
    for(int i=cur[u];i&&res<lim;i=e[i].nxt)
    {
        cur[u]=i;
        int y=e[i].to;
        if(dep[y]!=dep[u]+1||!e[i].c) continue;
        int t=find(y,min(e[i].c,lim-res));
        if(!t) dep[y]=0;
        e[i].c-=t; e[i^1].c+=t; res+=t;
    }
    return res;
}
int dinic()
{
    int ans=0, flow;
    while(bfs())
        while(flow=find(S,inf))
            ans+=flow;
    return ans;
}
int main()
{
    // freopen("testdata.in","r",stdin);
    Cases=read();
    while(Cases--)
    {
        N=read(); M=read(); 
        S=2*N+1; T=S+1; siz=2*N+2;
        for(int i=1;i<=siz;i++) head[i]=0;
        cnt=1;
        for(int i=1;i<=M;i++)
        {
            int u=read(), v=read();
            ae(u,v+N,1);
        }
        for(int i=1;i<=N;i++)
            ae(S,i,1), ae(i+N,T,1);
        int match=dinic();  
        // cout << "match=" << match << '\n';
        int s1=0, s2=0;
        while(!q1.empty()) q1.pop();
        while(!q2.empty()) q2.pop();
        for(int i=1;i<=siz;i++) vis[i]=0;
        q1.push(S);
        while(!q1.empty())
        {
            int x=q1.front(); q1.pop();
            if(vis[x]) continue; vis[x]=1;
            // cout << "x=" << x << '\n';
            for(int i=head[x];i;i=e[i].nxt)
            {
                int y=e[i].to;
                if(!e[i].c||y==S||y==T) continue;
                s1+=(y<=N); q1.push(y);
            }
        }
        // cout << "s1=" << s1 << '\n';
        for(int i=1;i<=siz;i++) vis[i]=0;
        q2.push(T);
        while(!q2.empty())
        {
            int x=q2.front(); q2.pop();
            if(vis[x]) continue; vis[x]=1;
            // cout << "x=" << x << '\n';
            for(int i=head[x];i;i=e[i].nxt)
            {
                int y=e[i].to;
                if(!e[i].c||y==T||y==S) continue;
                s2+=(y>N); q2.push(y);
            }
        }
        ll ans=1ll*s1*s2;
        cout << ans << '\n';
        for(int i=1;i<=siz;i++) head[i]=0;
        cnt=1;
    }
    return (0-0);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5580kb

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: 2ms
memory: 5772kb

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:

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

result:

wrong answer 1st numbers differ - expected: '6', found: '9'