QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#722670#6526. CanvasHNO3ilWA 0ms20524kbC++141.8kb2024-11-07 19:51:542024-11-07 19:51:54

Judging History

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

  • [2024-11-07 19:51:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:20524kb
  • [2024-11-07 19:51:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
#define mp make_pair
int head[N],cnt,z[N],tp,dfn[N],low[N],ct,bl[N],tot,rd[N],vis[N];bool in[N],fl[N],as[N];
struct edge{int to,nxt;}e[N<<1];vector<pair<int,pair<int,int>>>q,g,w;
void add(int u,int v){e[++cnt]={v,head[u]},head[u]=cnt;}
void dfs(int u){dfn[u]=low[u]=++ct,z[++tp]=u,in[u]=1;
	for(int i=head[u];i;i=e[i].nxt)
		if(!dfn[e[i].to])dfs(e[i].to),low[u]=min(low[u],low[e[u].to]);
		else if(in[e[i].to])low[u]=min(low[u],dfn[e[i].to]);
	if(dfn[u]==low[u]){++tot;do bl[z[tp]]=tot,in[z[tp]]=1;while(z[tp--]!=u);}
}
int main(){int T;cin>>T;
	while(T--){
		memset(head,0,sizeof(head)),memset(vis,0,sizeof(vis)),memset(rd,0,sizeof(rd)),
		memset(dfn,0,sizeof(dfn)),memset(fl,0,sizeof(fl)),memset(as,0,sizeof(as)),cnt=ct=0;q.clear(),g.clear(),w.clear();
		int n,m,ans=0;cin>>n>>m;
		for(int i=1,u,v,x,y;i<=m;i++){cin>>u>>x>>v>>y;if(!fl[u])ans+=2,fl[u]=1;if(!fl[v])ans+=2,fl[v]=1;
			if(x==1&&y==2)add(u,v),w.push_back(mp(u,mp(v,i)));else if(x==2&&y==1)add(v,u),w.push_back(mp(v,mp(u,i)));
			else if(x==2&&y==2)q.push_back(mp(u,mp(v,i)));else g.push_back(mp(u,mp(v,i)));
		}
		for(int i=1;i<=n;i++)if(!dfn[i])dfs(i);
		for(pair<int,pair<int,int>>t:q)if(bl[t.first]==bl[t.second.first])vis[bl[t.first]]=t.second.second;
		for(pair<int,pair<int,int>>t:w)if(bl[t.first]!=bl[t.second.first])++rd[bl[t.second.first]];
		for(int i=1;i<=tot;i++)if(!rd[i]&&!vis[i]&&fl[i])--ans;
		cout<<ans<<endl;
		for(int i=1;i<=tot;i++)if(!rd[i]&&vis[i])cout<<vis[i]<<' ',as[vis[i]]=1;
		for(pair<int,pair<int,int>>t:q)if(!as[t.second.second])cout<<t.second.second<<' ';
		for(pair<int,pair<int,int>>t:w)cout<<t.second.second<<' ';
		for(pair<int,pair<int,int>>t:g)cout<<t.second.second<<' ';cout<<endl;
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 20524kb

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
3 1 2 4 
5
1 2 

result:

wrong answer Participant's solution is incorrect. (test case 1)