QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#536142#4578. LabyrinthLavine#WA 2ms9428kbC++141.3kb2024-08-28 19:03:542024-08-28 19:03:54

Judging History

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

  • [2024-08-28 19:03:54]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9428kb
  • [2024-08-28 19:03:54]
  • 提交

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");
}

Details

Tip: Click on the bar to expand more detailed information

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