QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#43202 | #4513. Slide Parade | aurelion_sol | 35 ✓ | 16266ms | 35708kb | C++14 | 1.6kb | 2022-08-08 14:48:32 | 2022-08-08 14:48:33 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a),_=int(b);i<=_;++i)
#define per(i,a,b) for(int i=int(a),_=int(b);i>=_;--i)
#define fi first
#define se second
using namespace std;
const int N=205,M=5005;
int T,n,m,u[M],v[M],mat[N],a[N][N],len,ans[N*M];
bool b[N][N],vis[N];
void Imp(int id){
printf("Case #%d: IMPOSSIBLE\n",id);
}
bool aug(int x){
if(vis[x]){
return 0;
}
vis[x]=1;
rep(i,1,n)if(b[x][i]&&(!mat[i]||aug(mat[i]))){
return mat[i]=x,1;
}
return 0;
}
bool dfs(int v,int u){
if(vis[v]){
return 0;
}
vis[v]=1;
if(mat[v]==u){
return 1;
}
int w=mat[v];
rep(i,1,n)if(b[w][i]&&dfs(i,u)){
mat[i]=w;
mat[v]=u;
return 1;
}
return 0;
}
void euler(int u){
rep(i,1,n)if(a[u][i]){
--a[u][i];
euler(i);
ans[++len]=u;
}
}
int main(){
//freopen("1.in","r",stdin);
scanf("%d",&T);
rep(id,1,T){
scanf("%d%d",&n,&m);
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
rep(i,1,m){
scanf("%d%d",&u[i],&v[i]);
b[u[i]][v[i]]=1;
}
memset(mat,0,sizeof(mat));
int cnt=0;
rep(i,1,n){
memset(vis,0,sizeof(vis));
cnt+=aug(i);
}
if(cnt<n){
Imp(id);
goto new_test;
}
rep(i,1,m){
memset(vis,0,sizeof(vis));
if(!dfs(v[i],u[i])){
Imp(id);
goto new_test;
}
rep(j,1,n){
++a[mat[j]][j];
}
}
len=0;
ans[++len]=1;
euler(1);
if(len!=n*m+1){
Imp(id);
goto new_test;
}
printf("Case #%d: %d\n",id,len);
per(i,len,1){
printf("%d%c",ans[i]," \n"[i==1]);
}
new_test:;
}
return 0;
}
详细
Test #1:
score: 11
Accepted
time: 1ms
memory: 4000kb
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: 51 1 3 1 3 1 4 2 3 1 4 2 3 1 4 2 3 4 2 3 4 2 5 1 4 2 5 1 4 2 5 1 4 2 5 1 4 2 5 1 4 2 5 3 5 3 5 3 5 3 5 1 Case #3: 51 1 4 2 3 1 4 2 3 1 4 2 3 1 4 2 3 1 4 2 3 1 4 3 5 1 4 3 5 1 4 3 5 1 4 3 5 1 4 5 2 3 5 2 5 2 5 2 5 2 5 1 Case #4: 19 1 2 1 2 1 2 1 3 1 3 1 3 2 3 2 3 2 3 1 Ca...
result:
ok (100 test cases)
Test #2:
score: 24
Accepted
time: 16266ms
memory: 35708kb
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: 1000001 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 1...
result:
ok (100 test cases)