QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#722664#6526. CanvasHNO3ilWA 0ms21564kbC++142.1kb2024-11-07 19:50:392024-11-07 19:50:40

Judging History

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

  • [2024-11-07 19:50:40]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:21564kb
  • [2024-11-07 19:50:39]
  • 提交

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;
		reverse(ass.begin(),ass.end());for(int i:ass)cout<<i<<' ';cout<<endl;
	}
	return 0;
}

详细

Test #1:

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

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
Wrong Answer
time: 0ms
memory: 21564kb

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:

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

result:

wrong answer Jury has better answer. Participant 18, jury 19 (test case 1)