QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#114677 | #5974. Bilingual | zwh2008 | 0 | 0ms | 0kb | C++14 | 1.3kb | 2023-06-22 21:01:36 | 2023-06-22 21:01:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5005,inf=2e9;
int n,cnt=1,Case,ct,s,t,tot,gap[N],d[N],h[N];
struct edge{int n,t,v;}e[N*20];
map<string,int>mp;
vector<string>a[N];
void add(int x,int y,int z){e[++cnt]={h[x],y,z},h[x]=cnt;}
void Add(int x,int y,int z){add(x,y,z),add(y,x,0);}
int isap(int x,int flow) {
if(x==t)return flow;
int res=0;
for(int i=h[x];i;i=e[i].n) {
int y=e[i].t;
if(e[i].v&&d[x]==d[y]+1) {
int k=isap(y,min(e[i].v,flow-res));
e[i].v-=k,e[i^1].v+=k,res+=k;
if(flow==res)return res;
}
}
if(!--gap[d[x]])d[s]=tot;
return ++gap[++d[x]],res;
}
int maxflow() {
memset(d,0,sizeof(d)),memset(gap,0,sizeof(gap));
int res=0;gap[0]=tot;while(d[s]<tot)res+=isap(s,inf);
return res;
}
void get(vector<string>&g) {
char ch;string w;g.clear();
do {
cin>>w;if(!mp.count(w))mp[w]=++ct;
g.push_back(w),ch=getchar();
}while(ch!='\n');
}
void solve() {
scanf("%d",&n),cnt=1,memset(h,0,sizeof(h)),mp.clear();
for(int i=1;i<=n;i++)get(a[i]);
s=2*ct+n+1,t=tot=s+1,Add(2*ct+2,t,inf);
for(auto i:a[1])Add(s,mp[i],inf);
for(int i=1;i<=n;i++)
for(auto j:a[i])Add(mp[j]+ct,ct*2+i,inf),Add(ct*2+i,mp[j],inf);
for(int i=1;i<=ct;i++)Add(i,i+ct,1),Add(i+ct,i,1);
printf("Case #%d: %d\n",++Case,maxflow());
}
int main() {
int tt;scanf("%d",&tt);
while(tt--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
25 2 he loves to eat baguettes il aime manger des baguettes 4 a b c d e f g h i j a b c i j f g h d e 4 he drove into a cul de sac elle a conduit sa voiture il a conduit dans un cul de sac il mange pendant que il conduit sa voiture 6 adieu joie de vivre je ne regrette rien adieu joie de vivre je ne ...
output:
Case #1: 1 Case #2: 4 Case #3: 3 Case #4: 8 Case #5: 979 Case #6: 995
result:
Subtask #2:
score: 0
Runtime Error
Test #2:
score: 0
Runtime Error
input:
25 2 he loves to eat baguettes il aime manger des baguettes 4 a b c d e f g h i j a b c i j f g h d e 4 he drove into a cul de sac elle a conduit sa voiture il a conduit dans un cul de sac il mange pendant que il conduit sa voiture 6 adieu joie de vivre je ne regrette rien adieu joie de vivre je ne ...
output:
Case #1: 1 Case #2: 4 Case #3: 3 Case #4: 8 Case #5: 761