QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#563683#9284. Christmas Children Circlezjy0001WA 0ms17228kbC++171.0kb2024-09-14 15:04:582024-09-14 15:04:58

Judging History

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

  • [2024-09-14 15:04:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:17228kb
  • [2024-09-14 15:04:58]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=5e5+5;
int n,rt=1;
int ans[N];
vector<int>A[N];
inline bool solve(int x,int y){
    ans[x]=y;
    if(x%n+1!=rt){
        if(binary_search(A[x%n+1].begin(),A[x%n+1].end(),y))
            return solve(x%n+1,y);
        else return solve(x%n+1,A[x%n+1][0]);
    }
    else{
        if(x==ans[rt])return 1;
        if(binary_search(A[x%n+1].begin(),A[x%n+1].end(),y))return 0;
        return 1;
    }
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    for(int i=1;i<=n;++i){
        int k;cin>>k;
        for(int j=0;j<k;++j){
            int x;cin>>x,A[i].emplace_back(x);
        }
        sort(A[i].begin(),A[i].end());
        if(A[i].size()<A[rt].size())rt=i;
    }
    for(auto i:A[rt])if(solve(rt,i)){
        for(int j=1;j<=n;++j)cout<<ans[j]<<" \n"[j==n];
        return 0;
    }
    cout<<"-1\n";
    return 0;
}
/*
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 15648kb

input:

3
2 1 4
2 4 3
2 3 1

output:

1 3 3

result:

ok Participant's answer is valid

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 17228kb

input:

4
1 2
1 3
1 5
1 2

output:

-1

result:

wrong answer answer always exists