QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#536140#4578. LabyrinthLavine#WA 2ms10068kbC++141.3kb2024-08-28 19:01:592024-08-28 19:01:59

Judging History

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

  • [2024-08-28 19:01:59]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10068kb
  • [2024-08-28 19:01:59]
  • 提交

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(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: 1ms
memory: 10068kb

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: 9208kb

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: 9112kb

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: 0ms
memory: 8796kb

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