QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#131128#6526. CanvasmariowongWA 5ms19912kbC++142.2kb2023-07-26 15:27:052023-07-26 15:27:07

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-26 15:27:07]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:19912kb
  • [2023-07-26 15:27:05]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

struct operation{
	int l,r,x,y;
}op[500005];
struct path{
	int des,id;
};
int a[500005],in[500005];
vector <path> edge[500005];
bool vis[500005];
vector <int> ans,v;
stack <int> s;
void dfs(int x){
	a[x]=2; vis[x]=true;
	for (auto i:edge[x]) v.push_back(i.id);
	for (auto i:edge[x]){
		if (!vis[i.des])
			dfs(i.des);
	}
}
int main(){
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--){
    	int n,m;
    	cin >> n >> m;
    	for (int i=1;i<=m;i++) cin >> op[i].l >> op[i].x >> op[i].r >> op[i].y;
		for (int i=1;i<=n;i++){
			a[i]=0; in[i]=0; 
			vis[i]=false;
			edge[i].clear(); 
		} 
		for (int i=1;i<=m;i++){
			if (op[i].x+op[i].y == 2) 
				a[op[i].l]=a[op[i].r]=1;
		}
		for (int i=1;i<=m;i++){
			if (op[i].x+op[i].y == 4) 
				a[op[i].l]=a[op[i].r]=2;
		}
		for (int i=1;i<=m;i++){
			if (op[i].x+op[i].y == 3){
				if (op[i].x == 1){
					in[op[i].r]++;
					edge[op[i].l].push_back({op[i].r,i});
				} 
				else 
				{
					in[op[i].l]++;
					edge[op[i].r].push_back({op[i].l,i});
				}
			}
		}
		ans.clear();
		for (int i=1;i<=m;i++){
			if (op[i].x+op[i].y == 2)
				ans.push_back(i); 
		}
		for (int i=1;i<=n;i++){
			if (in[i] == 0 && edge[i].empty()) 
				vis[i]=true;
		}
		for (int i=1;i<=n;i++){
			if (in[i] == 0 && !vis[i]){
				v.clear();
				bool gg=false;
				if (a[i] == 0 || a[i] == 1) gg=true;
				dfs(i);
				if (gg) a[i]=1;
				reverse(v.begin(),v.end());
				for (auto j:v) ans.push_back(j);
			}	
		}
		for (int i=1;i<=n;i++){
			if (a[i] == 2 && !vis[i]){
				v.clear();
				dfs(i);
				reverse(v.begin(),v.end());
				for (auto j:v) ans.push_back(j);
			}	
		}
		for (int i=1;i<=n;i++){
			if (!vis[i] && !edge[i].empty()){
				v.clear();
				bool gg=false;
				if (a[i] == 0) gg=true;
				dfs(i);
				if (gg) a[i]=1;
				reverse(v.begin(),v.end());
				for (auto j:v) ans.push_back(j);
			}	
		}
		for (int i=1;i<=m;i++){
			if (op[i].x+op[i].y == 4)
				ans.push_back(i);
		}
		int sum=0;
		for (int i=1;i<=n;i++) sum+=a[i];
		cout << sum << "\n";
		for (int i=0;i<ans.size();i++) cout << ans[i] << " ";
		cout << "\n";
	}
    return 0;
}									

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 19220kb

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: 19912kb

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:

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

result:

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