QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84714#4513. Slide Paradefansizhe0 12091ms34976kbC++231.7kb2023-03-06 17:39:562023-03-06 17:39:58

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 17:39:58]
  • 评测
  • 测评结果:0
  • 用时:12091ms
  • 内存:34976kb
  • [2023-03-06 17:39:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<int> edge[405];
int eid[205][205];
int vis[405];
int ex[5005],ey[5005];
int to[405];
int num[5005];
int mat[205][205];
int dfs(int x){
	vis[x]=1;
	for(int y:edge[x])if(!to[y]){to[x]=y,to[y]=x;return 1;}
	for(int y:edge[x])if(!vis[to[y]]&&dfs(to[y])){to[x]=y,to[y]=x;return 1;}
	return 0;
}
stack<int> st;
void solve(int x){
	for(int y=1;y<=n;y++)if(mat[x][y])mat[x][y]--,solve(y);
	st.push(x);
}
int main(){
	int _;scanf("%d",&_);
	for(int __=1;__<=_;__++){
		scanf("%d%d",&n,&m);
		for(int i=1;i<=2*n;i++)edge[i].clear();
		memset(num,0,sizeof(num));
		memset(to,0,sizeof(to));
		memset(mat,0,sizeof(mat));
		for(int i=1;i<=m;i++){
			int x,y;scanf("%d%d",&x,&y);
			edge[x].push_back(y+n);
			edge[y+n].push_back(x);
			ex[i]=x,ey[i]=y;
			eid[x][y]=i;
		}
		int nosol=0;
		for(int i=1;i<=n;i++){
			memset(vis,0,sizeof(vis));
			if(!dfs(i)){nosol=1;break;}
		}
		if(nosol){printf("Case #%d: IMPOSSIBLE\n",__);continue;}
		for(int i=1;i<=n;i++)num[eid[i][to[i]-n]]++;
		for(int i=1;i<=m;i++)if(!num[i]){
			memset(vis,0,sizeof(vis));
			int x=ex[i],y=ey[i]+n,tx=to[y],ty=to[x];
			to[x]=y,to[y]=x;vis[x]=1;
			to[tx]=to[ty]=0;
			if(!dfs(tx)){nosol=1;break;}
			for(int j=1;j<=n;j++)num[eid[j][to[j]-n]]++;
		}
		if(nosol){printf("Case #%d: IMPOSSIBLE\n",__);continue;}
		for(int i=1;i<=m;i++)mat[ex[i]][ey[i]]=num[i];
		solve(1);
		for(int i=1;i<=n&&!nosol;i++)
			for(int j=1;j<=n&&!nosol;j++)if(mat[i][j])nosol=1;
		if(nosol){printf("Case #%d: IMPOSSIBLE\n",__);continue;}
		printf("Case #%d: %d\n",__,st.size());
		while(!st.empty())printf("%d ",st.top()),st.pop();puts("");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 3784kb

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:

Case #1: IMPOSSIBLE
Case #2: 16
1 3 1 4 2 3 4 2 5 1 4 2 5 3 5 1 
Case #3: 16
1 4 2 3 1 4 3 1 4 5 2 3 5 2 5 1 
Case #4: 7
1 2 1 3 2 3 1 
Case #5: 16
1 2 3 1 2 4 3 1 5 2 4 5 4 5 3 1 
Case #6: 17
1 2 1 3 1 3 1 4 2 3 4 2 4 3 4 2 1 
Case #7: 11
1 2 1 3 5 4 2 4 5 3 1 
Case #8: 16
1 3 5 1 4 2 1 4 2 3 5 2 4...

result:

wrong answer Integer 6 violates the range [1, 2] (test case 26)

Test #2:

score: 0
Wrong Answer
time: 12091ms
memory: 34976kb

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:

Case #1: IMPOSSIBLE
Case #2: IMPOSSIBLE
Case #3: 658601
1 18 13 9 5 3 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17 7 4 17...

result:

wrong answer invalid move (from 1 to 1) (test case 29)