Submission #71482085


Source Code Expand

/* Code By WCM */
/*
Date:
大致思路:
复杂度:
期望得分:
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <vector>
#include <queue>
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define int long long

using namespace std;

inline int read();
void write(int);
void writeln(int);

signed main() {

//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);

	int n = read(), m = read();
	vector <vector <int> > G(n + 1);
	while(m--) {
		int x = read(), y = read();
		G[y].pb(x); 
	}
	int Q = read();
	vector <bool> vis(n + 1, 0);
	queue <int> q; 
	while(Q--) {
		int op = read(), v = read();
		if(op == 1) {
			if(!vis[v]) {
				vis[v] = 1, q.push(v);
				while(!q.empty()) {
					int u = q.front(); q.pop();
					for(int vv : G[u]) if(!vis[vv]) vis[vv] = 1, q.push(vv);
				}
			}
		}
		else puts(vis[v] ? "Yes" : "No");
	}
	
//	printf("\nThe time used: ");
//	printf("%.2lfs",(double)clock()/CLOCKS_PER_SEC);

	return 0;

}

inline int read() {
	int res = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
	while(ch >= '0' && ch <= '9') res = (res << 1) + (res << 3) + (ch ^ 48), ch = getchar();
	return res * f;
}

void write(int x) {
	static int sta[35];
	int top = 0;
	do { sta[top++] = x % 10, x /= 10; } while(x);
	while(top) putchar(sta[--top] ^ 48);
}

void writeln(int x) {
	write(x);
	putchar('\n');
}


Submission Info

Submission Time
Task D - Reachability Query 2
User WZwangchongming
Language C++23 (GCC 15.2.0)
Score 425
Code Size 1616 Byte
Status AC
Exec Time 63 ms
Memory 19764 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 1
AC × 30
Set Name Test Cases
Sample sample_01.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, sample_01.txt
Case Name Status Exec Time Memory
min.txt AC 1 ms 3568 KiB
random_01.txt AC 53 ms 16584 KiB
random_02.txt AC 51 ms 16576 KiB
random_03.txt AC 28 ms 7720 KiB
random_04.txt AC 40 ms 9628 KiB
random_05.txt AC 11 ms 3912 KiB
random_06.txt AC 9 ms 3668 KiB
random_07.txt AC 17 ms 5472 KiB
random_08.txt AC 52 ms 14528 KiB
random_09.txt AC 14 ms 4932 KiB
random_10.txt AC 15 ms 5528 KiB
random_11.txt AC 36 ms 8532 KiB
random_12.txt AC 56 ms 15668 KiB
random_13.txt AC 13 ms 5576 KiB
random_14.txt AC 11 ms 4712 KiB
random_15.txt AC 32 ms 9544 KiB
random_16.txt AC 39 ms 10548 KiB
random_17.txt AC 33 ms 14984 KiB
random_18.txt AC 42 ms 19764 KiB
random_19.txt AC 8 ms 3680 KiB
random_20.txt AC 13 ms 4876 KiB
random_21.txt AC 48 ms 16172 KiB
random_22.txt AC 45 ms 19688 KiB
random_23.txt AC 31 ms 17276 KiB
random_24.txt AC 40 ms 19672 KiB
random_25.txt AC 63 ms 19688 KiB
random_26.txt AC 63 ms 19672 KiB
random_27.txt AC 44 ms 19688 KiB
random_28.txt AC 30 ms 14980 KiB
sample_01.txt AC 1 ms 3592 KiB