QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#114678#5974. Bilingualzwh20080 0ms0kbC++141.4kb2023-06-22 21:03:482023-06-22 21:03:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-22 21:03:51]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-06-22 21:03:48]
  • 提交

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*50];
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]);
	if(2*ct+n>5000)while(1);
	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
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

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
Time Limit Exceeded

Test #2:

score: 0
Time Limit Exceeded

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

result: