QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#68140 | #4883. Bayan Testing | A_zjzj | WA | 2ms | 3756kb | C++14 | 741b | 2022-12-14 19:11:45 | 2022-12-14 19:11:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;using ll=long long;const int N=2e5+10;
int T,n,m,cnt,fa[N];struct zj{int l,r;}a[N];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
void merge(int x,int y){fa[find(x)]=find(y);}
void get(){
cnt=0;scanf("%d%d",&n,&m);for(int i=1;i<=m*2;i++)scanf("%d%d",&a[i].l,&a[i].r);iota(fa,fa+1+n,0);
sort(a+1,a+1+m*2,[](zj x,zj y){return x.l^y.l?x.l<y.l:x.r>y.r;});for(int i=1,j;i<=m*2;i=j+1){
for(j=i+1;j<=m*2&&a[j].l==a[i].l;j++);if(a[i].l==a[i].r)++i;
if(cnt+j-i<=m)merge(a[i].l,a[j-1].r),cnt+=j-i;else merge(a[i].l,a[i+(m-cnt)].r),cnt=m;
}if(cnt<m)puts("-1");else for(int i=1;i<=n;i++)printf("%d%c",find(i),"\n "[i<n]);
}
int main(){
for(scanf("%d",&T);T--;get());return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3756kb
input:
3 2 1 1 1 2 2 6 2 1 3 4 6 2 4 3 5 4 3 1 2 1 1 2 2 2 3 3 3 3 4
output:
-1 5 2 5 4 5 6 -1
result:
wrong answer jury found answer, but participant don't (test case 3)