QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#553586 | #5984. Taking Over The World | masterhuang | 36 ✓ | 119ms | 30584kb | C++23 | 1.8kb | 2024-09-08 16:10:12 | 2024-09-08 16:10:12 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
const int N=4e4+5,M=8e6+5;
struct edge{int to,nex,w;}e[M<<1];
int TT,n,m,k,S,T,tot,head[N],_head[N],d[N];
basic_string<int>g[N];
inline void add(int u,int v,int w)
{
e[++tot]={v,head[u],w};head[u]=tot;
e[++tot]={u,head[v],0};head[v]=tot;
}
inline bool bfs()
{
memset(d,0,sizeof(d));d[S]=1;queue<int>q;q.push(S);
while(!q.empty())
{
int t=q.front();q.pop();
for(int i=head[t];i;i=e[i].nex)
{
int to=e[i].to;
if(!d[to]&&e[i].w>0) d[to]=d[t]+1,q.push(to);
}
}
return d[T];
}
int dfs(int x,int F)
{
if(x==T) return F;int tt=F;
for(int &i=_head[x];i;i=e[i].nex)
{
int to=e[i].to;
if(d[to]==d[x]+1&&e[i].w>0)
{
int t=dfs(to,min(tt,e[i].w));
tt-=t;e[i].w-=t;e[i^1].w+=t;
if(!tt) break;
}
}
if(tt==F) d[x]=0;return F-tt;
}
inline int dinic()
{
int s=0;
while(bfs())
{
memcpy(_head,head,sizeof(head)),s+=dfs(S,2e9);
if(s>k) return s;
}
return s;
}
inline bool chk(int x)
{
tot=1;memset(head,0,sizeof(head));
S=2;T=(x+1)*2*n-1;
for(int i=1;i<=x;i++)
{
for(int j=n-1;j>1;j--)
add((i-1)*2*n+j*2-1,(i-1)*2*n+j*2,1),add((i-1)*2*n+j*2-1,i*2*n+j*2,1e9);
for(int j=1;j<=n;j++) for(int k:g[j])
add((i-1)*2*n+j*2,i*2*n+(k*2)-1,1e9);
add((i-1)*2*n+n*2-1,i*2*n+(n*2)-1,1e9);
}
return dinic()<=k;
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>TT;
for(int c=1;c<=TT;c++)
{
cin>>n>>m>>k;k--;
for(int i=1,u,v;i<=m;i++) cin>>u>>v,u++,v++,g[u]+=v,g[v]+=u;
int l=1,r=n+k,mid,ans=0;
while(l<=r) mid=(l+r)>>1,chk(mid)?ans=mid,l=mid+1:r=mid-1;
cout<<"Case #"<<c<<": "<<ans+2<<"\n";
for(int i=1;i<=n;i++) g[i].clear();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 7
Accepted
Test #1:
score: 7
Accepted
time: 92ms
memory: 29716kb
input:
100 91 107 3 48 84 21 39 1 3 21 63 32 62 71 77 1 61 69 75 36 81 0 49 9 83 56 90 9 87 74 86 4 31 12 33 8 18 26 29 0 76 56 77 7 14 11 43 68 90 53 74 35 72 50 88 10 17 65 78 12 85 0 33 22 89 28 55 56 85 0 67 27 49 46 63 37 46 42 79 3 31 13 26 19 85 24 59 15 41 57 66 58 75 30 53 3 65 0 31 24 90 38 70 12...
output:
Case #1: 5 Case #2: 7 Case #3: 2 Case #4: 6 Case #5: 6 Case #6: 5 Case #7: 4 Case #8: 3 Case #9: 5 Case #10: 8 Case #11: 6 Case #12: 5 Case #13: 2 Case #14: 4 Case #15: 5 Case #16: 9 Case #17: 5 Case #18: 2 Case #19: 7 Case #20: 7 Case #21: 9 Case #22: 101 Case #23: 8 Case #24: 6 Case #25: 2 Case #2...
result:
ok 100 lines
Subtask #2:
score: 29
Accepted
Test #2:
score: 29
Accepted
time: 119ms
memory: 30584kb
input:
100 7 11 3 3 5 4 6 3 4 2 5 1 4 5 6 0 1 0 2 2 4 0 3 1 5 22 23 5 5 11 5 19 9 18 0 8 3 20 6 15 13 14 1 9 3 4 6 8 2 16 10 12 11 17 7 21 12 18 7 20 0 10 14 21 1 21 15 16 2 13 0 19 4 17 22 23 6 4 10 6 18 12 18 0 17 0 11 3 15 12 19 1 13 11 15 2 6 9 21 3 20 7 17 16 19 8 21 7 14 5 14 4 21 5 8 1 10 13 20 2 9 ...
output:
Case #1: 5 Case #2: 10 Case #3: 10 Case #4: 11 Case #5: 17 Case #6: 8 Case #7: 7 Case #8: 11 Case #9: 101 Case #10: 12 Case #11: 6 Case #12: 9 Case #13: 6 Case #14: 18 Case #15: 17 Case #16: 8 Case #17: 6 Case #18: 18 Case #19: 10 Case #20: 6 Case #21: 8 Case #22: 9 Case #23: 2 Case #24: 6 Case #25:...
result:
ok 100 lines
Extra Test:
score: 0
Extra Test Passed