提出 #70523725


ソースコード 拡げる

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int t; cin >> t;
	while (t--) {
		int n, m; cin >> n >> m;
		vector to(n, vector<int>());
		rep(i, m) {
			int u, v; cin >> u >> v;
			u--, v--;
			to[u].push_back(v);
		}
		vector<int>p(n), q(n);
		rep(i, n) {
			cin >> p[i], p[i]--;
			q[p[i]] = i;
		}

		vector<int>deg(n);
		int ans = n;
		rep(i, n)for (auto j : to[i])deg[j]++;
		for (int i = 0; i < n;) {
			int j = i + 1;
			while (j < n && deg[q[j]] == 0)j++;
			rep2(k, i, j)for (auto l : to[q[k]])deg[l]--;
			i = j;
			ans--;
		}
		cout << ans << endl;
	}
	return 0;
}

提出情報

提出日時
問題 A - Communicate Topological Order
ユーザ kwm_t
言語 C++ 23 (gcc 12.2)
得点 700
コード長 1475 Byte
結果 AC
実行時間 56 ms
メモリ 14264 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 700 / 700
結果
AC × 1
AC × 70
セット名 テストケース
Sample sample.txt
All dense_1.txt, dense_10.txt, dense_2.txt, dense_3.txt, dense_4.txt, dense_5.txt, dense_6.txt, dense_7.txt, dense_8.txt, dense_9.txt, line_1.txt, line_10.txt, line_2.txt, line_3.txt, line_4.txt, line_5.txt, line_6.txt, line_7.txt, line_8.txt, line_9.txt, random_1.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_2.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_3.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_4.txt, random_40.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt, sample.txt, small_1.txt, small_2.txt, small_3.txt, small_4.txt, small_5.txt, small_6.txt, small_7.txt, small_8.txt, small_9.txt
ケース名 結果 実行時間 メモリ
dense_1.txt AC 27 ms 6572 KiB
dense_10.txt AC 26 ms 6832 KiB
dense_2.txt AC 26 ms 7208 KiB
dense_3.txt AC 26 ms 5708 KiB
dense_4.txt AC 26 ms 7092 KiB
dense_5.txt AC 29 ms 10296 KiB
dense_6.txt AC 26 ms 5520 KiB
dense_7.txt AC 29 ms 8888 KiB
dense_8.txt AC 29 ms 9416 KiB
dense_9.txt AC 26 ms 5544 KiB
line_1.txt AC 40 ms 6844 KiB
line_10.txt AC 44 ms 8928 KiB
line_2.txt AC 44 ms 10060 KiB
line_3.txt AC 40 ms 9016 KiB
line_4.txt AC 35 ms 9456 KiB
line_5.txt AC 39 ms 6568 KiB
line_6.txt AC 44 ms 7040 KiB
line_7.txt AC 44 ms 14264 KiB
line_8.txt AC 41 ms 8824 KiB
line_9.txt AC 41 ms 7508 KiB
random_1.txt AC 51 ms 13600 KiB
random_10.txt AC 26 ms 11640 KiB
random_11.txt AC 40 ms 8600 KiB
random_12.txt AC 50 ms 13632 KiB
random_13.txt AC 43 ms 9676 KiB
random_14.txt AC 38 ms 10424 KiB
random_15.txt AC 51 ms 13632 KiB
random_16.txt AC 39 ms 8368 KiB
random_17.txt AC 35 ms 7728 KiB
random_18.txt AC 39 ms 13072 KiB
random_19.txt AC 33 ms 9144 KiB
random_2.txt AC 52 ms 13644 KiB
random_20.txt AC 49 ms 13540 KiB
random_21.txt AC 48 ms 13544 KiB
random_22.txt AC 52 ms 13556 KiB
random_23.txt AC 51 ms 11764 KiB
random_24.txt AC 44 ms 13312 KiB
random_25.txt AC 51 ms 12732 KiB
random_26.txt AC 25 ms 9376 KiB
random_27.txt AC 42 ms 8868 KiB
random_28.txt AC 56 ms 13604 KiB
random_29.txt AC 50 ms 13576 KiB
random_3.txt AC 28 ms 12024 KiB
random_30.txt AC 39 ms 8276 KiB
random_31.txt AC 42 ms 9336 KiB
random_32.txt AC 45 ms 9508 KiB
random_33.txt AC 31 ms 8352 KiB
random_34.txt AC 50 ms 13628 KiB
random_35.txt AC 40 ms 7148 KiB
random_36.txt AC 42 ms 8392 KiB
random_37.txt AC 50 ms 13572 KiB
random_38.txt AC 29 ms 12000 KiB
random_39.txt AC 40 ms 6940 KiB
random_4.txt AC 45 ms 11492 KiB
random_40.txt AC 25 ms 11504 KiB
random_5.txt AC 45 ms 8768 KiB
random_6.txt AC 53 ms 13620 KiB
random_7.txt AC 50 ms 13564 KiB
random_8.txt AC 39 ms 8092 KiB
random_9.txt AC 44 ms 9948 KiB
sample.txt AC 1 ms 3344 KiB
small_1.txt AC 32 ms 3436 KiB
small_2.txt AC 32 ms 3480 KiB
small_3.txt AC 31 ms 3412 KiB
small_4.txt AC 32 ms 3476 KiB
small_5.txt AC 32 ms 3472 KiB
small_6.txt AC 32 ms 3400 KiB
small_7.txt AC 32 ms 3436 KiB
small_8.txt AC 32 ms 3464 KiB
small_9.txt AC 13 ms 3400 KiB