QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#536142 | #4578. Labyrinth | Lavine# | WA | 2ms | 9428kb | C++14 | 1.3kb | 2024-08-28 19:03:54 | 2024-08-28 19:03:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,m,s,f[N],vis[N];
vector<int>e[N],rs1,rs2;
void slv(int x,vector<int>&rs){
rs.push_back(x);
if(x==s)return;
else slv(f[x],rs);
}
void Fin(){
puts("Possible");
printf("%d\n",(int)rs1.size());
for(int i=(int)rs1.size()-1;~i;i--){
printf("%d%c",rs1[i],(i)? ' ':'\n');
}
printf("%d\n",(int)rs2.size());
for(int i=(int)rs2.size()-1;~i;i--){
printf("%d%c",rs2[i],(i)? ' ':'\n');
}
exit(0);
}
void dfs(int x,int y){
// printf("___%d %d\n",x,y);
vis[x]=y;
for(auto to:e[x]){
if(to==s)continue;
else if(vis[to]==y)continue;
else if(vis[to]){
// puts("??????");
rs1.push_back(to);
slv(x,rs1);
slv(to,rs2);
// puts("<<<");
Fin();
}else {
f[to]=x;
dfs(to,y);
}
}
}
int main(){
scanf("%d %d %d",&n,&m,&s);
for(int i=1;i<=m;++i){
int x,y;
scanf("%d %d",&x,&y);
e[x].push_back(y);
}
for(auto y:e[s]){
if(vis[y]){
rs1.push_back(y),rs1.push_back(s);
slv(y,rs2);
}
f[y]=s;
dfs(y,y);
}
puts("Impossible");
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 8500kb
input:
5 5 1 1 2 2 3 1 4 4 3 3 5
output:
Possible 3 1 4 3 3 1 2 3
result:
ok n=5, m=5: possible
Test #2:
score: 0
Accepted
time: 2ms
memory: 8504kb
input:
5 5 1 1 2 2 3 3 4 2 5 5 4
output:
Impossible
result:
ok n=5, m=5: impossible
Test #3:
score: 0
Accepted
time: 0ms
memory: 8320kb
input:
3 3 2 1 2 2 3 3 1
output:
Impossible
result:
ok n=3, m=3: impossible
Test #4:
score: -100
Wrong Answer
time: 2ms
memory: 9428kb
input:
5 5 1 1 2 2 3 3 4 4 5 1 5
output:
Impossible
result:
wrong answer Jury has answer, but participant doesn't