QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#563683 | #9284. Christmas Children Circle | zjy0001 | WA | 0ms | 17228kb | C++17 | 1.0kb | 2024-09-14 15:04:58 | 2024-09-14 15:04:58 |
Judging History
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