QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#84661 | #4513. Slide Parade | Bird | 35 ✓ | 3979ms | 39468kb | C++14 | 1.3kb | 2023-03-06 16:39:37 | 2023-03-06 16:39:39 |
Judging History
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;
}
return 0;
}
inline void Dfs(int x)
{
for(int &i=head[x];i<(int)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;
}
详细
Test #1:
score: 11
Accepted
time: 1ms
memory: 3564kb
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 4 2 5 1 4 2 5 3 1 4 2 3 5 1 4 2 5 3 1 4 2 5 3 1 3 4 2 5 1 4 2 3 5 1 4 2 3 5 1 4 2 3 5 1 4 2 5 3 1 Case #3: 51 1 4 2 3 5 1 4 2 3 5 1 4 3 1 4 3 1 4 2 5 2 5 2 3 5 1 4 2 3 5 1 4 3 1 4 5 2 5 2 3 1 4 2 3 5 2 5 1 4 3 1 Case #4: 19 1 2 3 1 3 2 1 3 2 1 2 3 1 2 3 1 3 2 1 Ca...
result:
ok (100 test cases)
Test #2:
score: 24
Accepted
time: 3979ms
memory: 39468kb
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 192 32 161 115 167 51 24 73 45 33 173 16 164 2 129 12 56 89 94 96 91 116 127 181 4 48 170 75 78 153 149 13 199 37 157 90 28 69 20 108 1 27 187 103 118 79 178 74 196 46 124 61 171 112 155 105 98 50 42 88 168 26 160 122 30 142 121 97 71 180...
result:
ok (100 test cases)