QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#252053 | #6526. Canvas | C1942huangjiaxu | WA | 0ms | 28392kb | C++14 | 2.4kb | 2023-11-15 15:13:19 | 2023-11-15 15:13:19 |
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,dfn[N],low[N],st[N],tp,co[N],col,id[N];
bool c1[N],c2[N],v2[N],us[N],vis[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){
while(!g[x].empty()){
int u=g[x].back();
g[x].pop_back();
int y=a[u].l^a[u].r^x;
p[ed--]=u;
dfs(y);
c2[y]=true,c2[x]=false;
}
}
void tarjan(int x){
dfn[x]=low[x]=++dfn[0],vis[x]=true,st[++tp]=x;
for(auto v:g[x]){
int u=a[v].l^a[v].r^x;
if(!dfn[u]){
tarjan(u);
low[x]=min(low[x],low[u]);
}else if(vis[u])low[x]=min(low[x],dfn[u]);
}
if(dfn[x]==low[x]){
co[x]=++col;
while(st[tp]!=x){
co[st[tp]]=col;
vis[st[tp]]=false;
--tp;
}
vis[x]=false,--tp;
}
}
bool cmp(int x,int y){
return co[x]>co[y];
}
void solve(){
scanf("%d%d",&n,&m);
bg=1,ed=m,dfn[0]=col=0;
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].r].push_back(i);
else g[a[i].l].push_back(i);
}
for(int i=1;i<=n;++i)if(!dfn[i])tarjan(i);
for(int i=1;i<=n;++i)id[i]=i;
sort(id+1,id+n+1,cmp);
for(int i=1;i<=n;++i)dfs(id[i]);
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: 0
Wrong Answer
time: 0ms
memory: 28392kb
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 12 2 1
result:
wrong answer Participant's solution is incorrect. (test case 2)