QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#723132#6526. CanvasHNO3ilWA 0ms36364kbC++142.2kb2024-11-07 21:15:012024-11-07 21:15:03

Judging History

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

  • [2024-11-07 21:15:03]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:36364kb
  • [2024-11-07 21:15:01]
  • 提交

answer

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 34052kb

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

result:

ok Correct. (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 36364kb

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

output:

19
13 7 5 6 4 3 11 10 2 9 1 12 

result:

wrong output format Unexpected end of file - int32 expected (test case 1)