QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84646#4513. Slide ParadeBird0 0ms0kbC++141.3kb2023-03-06 16:32:342023-03-06 16:33:55

Judging History

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

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

answer

#include<bits/stdc++.h>
#define N 200
#define M 5000
using namespace std;
int T,n,m,match[N+5],u[M+5],v[M+5],st[N*M+5],top,head[N+5];
vector<int> e[N+5],E[N+5];
bool vis[N+5];
inline bool dfs(int x)
{
	for(int y:e[x]) if(!vis[y])
	{
		vis[y]=1;
		if(!match[y] || dfs(match[y]))
			return match[y]=x,1;
	}
}
inline void Dfs(int x)
{
	for(int &i=head[x];i<E[x].size();)
		Dfs(E[x][i++]),st[++top]=x;
}
inline void solve()
{
	for(int i=1;i<=n;++i)
	{
		memset(vis+1,0,n);
		if(!dfs(i)) return puts("IMPOSSIBLE"),void();
	}
	for(int i=1;i<=m;++i)
	{
		if(match[v[i]]!=u[i])
		{
			for(int j=1;j<=n;++j) if(match[j]==u[i]) {match[j]=0;break;}
			int temp=match[v[i]];match[v[i]]=u[i];
			memset(vis+1,0,n),vis[v[i]]=1;
			if(!dfs(temp)) return puts("IMPOSSIBLE"),void();
		}
		for(int j=1;j<=n;++j)
			E[match[j]].push_back(j);
	}
	st[top=0]=1,memset(head+1,0,n<<2),Dfs(1);
	if(top!=n*m) return puts("IMPOSSIBLE"),void();
	printf("%d\n",top+1);
	for(int i=top;~i;--i) printf("%d%c",st[i]," \n"[i==0]);
}
int main()
{
	scanf("%d",&T);
	for(int test=1;test<=T;++test)
	{
		scanf("%d %d",&n,&m);
		for(int i=1;i<=n;++i) e[i].clear(),E[i].clear();
		memset(match+1,0,n<<2);
		for(int i=1;i<=m;++i)
		{
			scanf("%d %d",u+i,v+i);
			e[u[i]].push_back(v[i]);
		}
		printf("Case #%d: ",test),solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

100
5 8
1 2
1 3
1 4
1 5
2 1
3 1
4 1
5 1
5 10
1 3
1 4
2 3
2 5
3 1
3 4
3 5
4 2
5 1
5 3
5 10
1 4
2 3
2 5
3 1
3 5
4 2
4 3
4 5
5 1
5 2
3 6
1 2
1 3
2 1
2 3
3 1
3 2
5 10
1 2
1 5
2 3
2 4
3 1
4 3
4 5
5 2
5 3
5 4
4 10
1 2
1 3
1 4
2 1
2 3
2 4
3 1
3 4
4 2
4 3
5 10
1 2
1 3
2 1
2 4
3 1
3 5
4 2
4 5
5 3
5 4
5 10
1 ...

output:


result:


Test #2:

score: 0
Runtime Error

input:

100
199 4980
1 95
1 96
1 105
1 124
1 130
1 131
1 135
1 137
1 139
1 140
1 141
1 147
1 155
1 172
1 174
1 179
1 183
1 188
1 193
1 196
1 197
2 3
2 5
2 13
2 14
2 17
2 20
2 24
2 26
2 30
2 41
2 44
2 45
2 52
2 56
2 67
2 70
2 71
2 74
2 78
2 84
2 85
2 90
2 92
2 93
2 97
2 107
2 111
2 113
2 122
2 124
2 128
2 13...

output:


result: