QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#722652#6526. CanvasHNO3ilWA 0ms22212kbC++142.1kb2024-11-07 19:49:062024-11-07 19:49:06

Judging History

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

  • [2024-11-07 19:49:06]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:22212kb
  • [2024-11-07 19:49:06]
  • 提交

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],fl[N];bool in[N],as[N];
struct edge{int to,nxt;}e[N<<1];vector<pair<int,pair<int,int>>>q,g,w;vector<int>ass;
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(),ass.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(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(int t=0;t<q.size();t++)if(bl[q[t].first]==bl[q[t].second.first])vis[bl[q[t].first]]=t;
		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[q[vis[i]].first]=fl[q[vis[i]].second.first]=2,ass.push_back(q[vis[i]].second.second),as[q[vis[i]].second.second]=1;
		for(pair<int,pair<int,int>>t:q)
			if(!as[t.second.second]){if(!fl[t.first])fl[t.first]=2;if(!fl[t.second.first])fl[t.second.first]=2;ass.push_back(t.second.second);}
		for(pair<int,pair<int,int>>t:w){if(!fl[t.first])fl[t.first]=1;if(!fl[t.second.first])fl[t.second.first]=2;ass.push_back(t.second.second);}
		for(pair<int,pair<int,int>>t:g){if(!fl[t.first])fl[t.first]=1;if(!fl[t.second.first])fl[t.second.first]=1;ass.push_back(t.second.second);}
		for(int i=1;i<=n;i++)ans+=fl[i];cout<<ans<<endl;
		for(int i:ass)cout<<i<<' ';cout<<endl;	
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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)