QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#252008 | #6526. Canvas | C1942huangjiaxu | RE | 0ms | 34516kb | C++14 | 1.8kb | 2023-11-15 14:28:59 | 2023-11-15 14:28:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int T,n,m,p[N],v1[N],bg,ed,ans;
bool c1[N],c2[N],v2[N],us[N];
queue<int>q;
vector<int>e[N],g[N];
struct node{
int l,x,r,y;
}a[N];
void add(int x){
if(!c2[x]){
c2[x]=true;
q.push(x);
}
}
void dfs(int x){
int u=g[x].back();
g[x].pop_back();
int y=a[u].l^a[u].r^x;
c2[x]=true,c2[y]=false;
p[++bg]=u;
dfs(y);
}
void solve(){
scanf("%d%d",&n,&m);
bg=1,ed=m;
for(int i=1;i<=n;++i)c1[i]=c2[i]=v1[i]=v2[i]=0,e[i].clear();
for(int i=1,l,x,r,y;i<=m;++i){
scanf("%d%d%d%d",&l,&x,&r,&y);
us[i]=false;
a[i]=node{l,x,r,y};
c1[l]=c1[r]=true;
if(x==1&&y==1){
us[i]=true;
p[bg++]=i;
continue;
}
if(x==2&&y==2){
us[i]=true;
p[ed--]=i;
add(l),add(r);
continue;
}
if(x==2)v2[l]=true;
else ++v1[l];
if(y==2)v2[r]=true;
else ++v1[r];
e[l].push_back(i);
e[r].push_back(i);
}
for(int i=1;i<=n;++i)if(v2[i]&&!v1[i])add(i);
for(int i=1;i<=m;++i)if(!us[i]){
if(a[i].x==1&&!v2[a[i].l]){
us[i]=true;
p[ed--]=i;
add(a[i].r);
}
if(a[i].y==1&&!v2[a[i].r]){
us[i]=true;
p[ed--]=i;
add(a[i].l);
}
}
while(!q.empty()){
int x=q.front();
q.pop();
for(auto v:e[x])if(!us[v]){
int y=x^a[v].l^a[v].r;
us[v]=true;
if((a[v].l==x)^(a[v].x>1)){
add(y);
p[ed--]=v;
}else{
p[bg++]=v;
--v1[y];
if(!v1[y])add(y);
}
}
}
for(int i=1;i<=m;++i)if(!us[i]){
if(a[i].x==2)g[a[i].l].push_back(i);
else g[a[i].r].push_back(i);
}
for(int i=1;i<=n;++i)if(!g[i].empty())dfs(i);
ans=0;
for(int i=1;i<=n;++i){
if(c1[i])++ans;
if(c2[i])++ans;
}
printf("%d\n",ans);
for(int i=1;i<=m;++i)printf("%d%c",p[i]," \n"[i==m]);
}
int main(){
scanf("%d",&T);
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 34516kb
input:
2 4 4 1 1 2 2 3 2 4 1 1 2 3 2 2 1 4 1 4 2 3 2 4 1 1 2 3 1
output:
7 4 2 1 3 5 2 1
result:
ok Correct. (2 test cases)
Test #2:
score: -100
Runtime Error
input:
1 10 13 1 1 2 2 2 1 3 2 1 2 3 1 3 1 4 2 4 1 5 2 5 1 6 2 4 2 6 1 7 1 8 2 8 1 9 2 7 2 9 1 5 2 9 1 8 2 10 2 1 1 10 1