Submission #73500767


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;

using i128 = __int128;
using u128 = unsigned __int128;

mt19937_64 mrand((u64)random_device{}() << 32 ^ random_device{}() ^
	chrono::high_resolution_clock::now().time_since_epoch().count());
template<class T = i64,class T2>T rnd(T l,T2 r){
return uniform_int_distribution<T>(l,r)(mrand);}

int main (){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);


	int n,m;
	cin >> n >> m;

	vector<vector<int>> a(n + 1);
	vector<int> tag(n + 1);
	vector<int> vis(n + 1,1e9);

	for (;m--;){
		int x,y;
		cin >> x >> y;

		a[x].push_back(y);
	}

	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;

	vis[1] = 1;
	q.emplace(1,1);

	for (;!q.empty();){
		auto [x,y] = q.top();
		q.pop();

		if (vis[y] != x) continue;

		for (auto i:a[y])
			if (max(x,i) < vis[i])
				q.emplace(vis[i] = max(x,i),i);
	}

	int ma = 0,cnt = 0;

	for (int i = 1;i <= n;i++){
		ma = max(ma,vis[i]);
		cnt -= tag[i];

		for (auto j:a[i])
			if (j > i&&!tag[j])
				cnt++,tag[j] = 1;

		if (ma > i){
			cout << "-1\n";
			continue;
		}

		cout << cnt << '\n';
	}
}

Submission Info

Submission Time
Task F - Reachable Set 2
User zyx2012
Language C++23 (GCC 15.2.0)
Score 500
Code Size 1250 Byte
Status AC
Exec Time 91 ms
Memory 22320 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 55
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, random_00.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, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3640 KiB
example_01.txt AC 1 ms 3592 KiB
hand_00.txt AC 72 ms 22144 KiB
hand_01.txt AC 53 ms 14700 KiB
hand_02.txt AC 64 ms 18256 KiB
hand_03.txt AC 60 ms 18212 KiB
hand_04.txt AC 17 ms 6064 KiB
hand_05.txt AC 50 ms 12920 KiB
hand_06.txt AC 64 ms 18196 KiB
hand_07.txt AC 63 ms 20204 KiB
hand_08.txt AC 8 ms 12972 KiB
hand_09.txt AC 1 ms 3644 KiB
hand_10.txt AC 1 ms 3600 KiB
hand_11.txt AC 21 ms 14788 KiB
hand_12.txt AC 70 ms 19656 KiB
hand_13.txt AC 71 ms 19668 KiB
hand_14.txt AC 67 ms 22148 KiB
hand_15.txt AC 58 ms 22264 KiB
hand_16.txt AC 62 ms 22320 KiB
random_00.txt AC 16 ms 5036 KiB
random_01.txt AC 24 ms 6188 KiB
random_02.txt AC 52 ms 10272 KiB
random_03.txt AC 17 ms 5620 KiB
random_04.txt AC 20 ms 5572 KiB
random_05.txt AC 52 ms 16940 KiB
random_06.txt AC 90 ms 18684 KiB
random_07.txt AC 91 ms 18772 KiB
random_08.txt AC 91 ms 18736 KiB
random_09.txt AC 16 ms 5240 KiB
random_10.txt AC 32 ms 6768 KiB
random_11.txt AC 72 ms 14580 KiB
random_12.txt AC 1 ms 3600 KiB
random_13.txt AC 5 ms 4528 KiB
random_14.txt AC 75 ms 17968 KiB
random_15.txt AC 1 ms 3608 KiB
random_16.txt AC 6 ms 4724 KiB
random_17.txt AC 52 ms 13276 KiB
random_18.txt AC 1 ms 3776 KiB
random_19.txt AC 6 ms 4908 KiB
random_20.txt AC 63 ms 15152 KiB
random_21.txt AC 17 ms 5364 KiB
random_22.txt AC 28 ms 6220 KiB
random_23.txt AC 75 ms 14456 KiB
random_24.txt AC 63 ms 12820 KiB
random_25.txt AC 62 ms 12864 KiB
random_26.txt AC 64 ms 12736 KiB
random_27.txt AC 51 ms 10252 KiB
random_28.txt AC 51 ms 10232 KiB
random_29.txt AC 51 ms 10228 KiB
random_30.txt AC 36 ms 7536 KiB
random_31.txt AC 36 ms 7388 KiB
random_32.txt AC 36 ms 7372 KiB
random_33.txt AC 27 ms 6220 KiB
random_34.txt AC 27 ms 6288 KiB
random_35.txt AC 27 ms 6212 KiB