QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#507426 | #5511. Minor Evil | SorahISA | AC ✓ | 1713ms | 102488kb | C++20 | 6.0kb | 2024-08-06 17:32:08 | 2024-08-06 17:32:09 |
Judging History
answer
#ifndef NYCU_MyGO
#define NYCU_MyGO
#include NYCU_MyGO __FILE__ NYCU_MyGO
void solve() {
int N, M; cin >> N >> M;
vector<vector<pii>> adj(N+1);
for (int i = 0; i < M; ++i) {
int u, v; cin >> u >> v;
adj[u].eb(v, i);
}
int S; cin >> S;
vector<int> kill(N+1, 0);
for (int i = 0; i < S; ++i) {
int s; cin >> s, kill[s] = 1;
}
string ans(M, 'N');
vector<int> max_id(N+1, -1);
Prior<pii> pq;
for (int i = 1; i <= N; ++i) { if (!kill[i]) max_id[i] = M, pq.ee(M, i); }
while (SZ(pq)) {
auto [lst_id, now] = pq.top(); pq.pop();
if (lst_id < max_id[now]) continue;
for (auto [x, id] : adj[now]) {
if (id < lst_id and chmax(max_id[x], id)) pq.ee(max_id[x], x);
}
}
for (int i = 1; i <= N; ++i) {
if (max_id[i] == -1) { cout << "NIE" << "\n"; return; }
if (max_id[i] < M) ans[max_id[i]] = 'T';
}
cout << "TAK" << "\n";
cout << ans << "\n";
}
int32_t main() {
fastIO();
int t = 1; cin >> t;
for (int _ = 1; _ <= t; ++_) {
solve();
}
return 0;
}
#else
#ifdef local
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int i64
using f80 = long double;
#define dobule f80
using pii = pair<int, int>;
template <typename T> using Prior = std::priority_queue<T>;
template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;
#define eb emplace_back
#define ef emplace_front
#define ee emplace
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())
#ifdef local
#define fastIO() void()
#define debug(...) \
fprintf(stderr, "\u001b[33m"), \
fprintf(stderr, "At [%s], line %d: (%s) = ", __FUNCTION__, __LINE__, #__VA_ARGS__), \
_do(__VA_ARGS__), \
fprintf(stderr, "\u001b[0m")
template <typename T> void _do(T &&_t) { cerr << _t << "\n"; }
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) { cerr << _t << ", ", _do(_u...); }
#else
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define debug(...) void()
#endif
template <typename T, typename U> bool chmin(T &lhs, U rhs) { return lhs > rhs ? lhs = rhs, 1 : 0; }
template <typename T, typename U> bool chmax(T &lhs, U rhs) { return lhs < rhs ? lhs = rhs, 1 : 0; }
#endif
/**
*
*
*
* iiiiii iiiiiiiiii iiiiiiiiiiiiii
* iiiiiiiiiiiii iiiiiii iiii iiiiiiiiiiiiiii ii iiii
* iiiiiiii iiiiiiiii iiii iiii iii iii iiiiiiiiii
* iiiiiii iiiiii iiii iiii ii iiiiiiiiii iiii iiii
* iiiiii iiiii iiii iiii iii iiii iiiiiiiiiiiiiiiii ii
* iiiiii iiiiiii iiiiiii iiiiiiii iii iiiiiiiiiiiiii iii iiii
* iiiiii iiiiiii iiiii ii iiii iiiiiiiiiii iiii iii iiii iiii iii
* iiiii iiiiiiii ii iiiii iiii iiiiiiiii iii iii iii iii ii iiii
* iiiiii iiiiiiii iiiii iiiii iiiiiiiiiiiiiiii iii iii ii iii iii iiii
* iiiii iiiiii iiii iiiiii iiiiiii iii iii iiii ii i ii iii iii
* iiiiii iiii iiiiiiiiiiiiiii iii iiii iiiii iii ii iii iii ii
* iiiii iiiiiiii iiiiiiiiii iiii iiiiiiiii ii iii ii
* iiiii iiiiii iiii iiiii iii ii ii i
* iiiiii iiiiiiii iiiii iiiii ii ii ii
* iiiii iiii iiii iiiiiiiiiiii ii
* iii iiii iiii iiiiiiii
* iiiii iiii
* iiii iiii
* iiii iiiii
* iii iiiii
* iii iiiii
* iii iiiiii
* iiiiiiiii
* iiiiii
*
*
*
**/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
input:
2 5 6 1 2 2 1 2 5 2 3 2 4 4 2 3 1 2 3 3 2 1 2 2 3 2 2 3
output:
TAK NTNTNT NIE
result:
ok correct (2 test cases)
Test #2:
score: 0
Accepted
time: 669ms
memory: 5892kb
input:
1000 5 6 1 2 2 1 2 5 2 3 2 4 4 2 3 1 2 3 3 2 1 2 2 3 2 2 3 2 1 1 2 1 1 2 1 1 2 1 2 3 3 2 1 3 2 3 2 1 3 3 3 1 3 1 3 1 2 2 1 3 3 3 1 2 1 3 1 3 1 2 3 3 2 1 2 3 1 3 1 2 3 3 3 2 3 1 1 2 3 1 2 3 3 3 1 2 2 3 1 2 1 3 3 3 2 1 1 2 1 2 1 2 3 3 2 1 1 3 1 3 1 1 3 3 3 2 3 2 2 3 1 3 3 3 3 2 1 2 2 1 1 1 3 3 2 1 3 2...
output:
TAK NTNTNT NIE NIE TAK T NIE NIE TAK TNN NIE NIE TAK NTN TAK NNT TAK TNN TAK NNT TAK NNT TAK NNT NIE NIE NIE NIE NIE NIE NIE NIE NIE TAK NTNN TAK TNTN NIE NIE NIE NIE NIE NIE NIE TAK TNTN TAK NNTN TAK NNNT TAK NNTN NIE TAK NNTN NIE NIE TAK NNNT NIE TAK NNTN NIE NIE NIE NIE NIE NIE NIE NIE TAK NNT NI...
result:
ok correct (1000 test cases)
Test #3:
score: 0
Accepted
time: 1340ms
memory: 91252kb
input:
13 1000000 1000000 486802 809159 104883 440551 501905 622668 279504 663293 839882 889531 125252 955226 270422 92128 363725 456993 513782 686348 292006 59538 112416 619373 150140 212648 891080 338487 348780 833779 186126 366730 294350 778236 173878 385135 831186 985800 868035 100117 752578 739541 457...
output:
NIE NIE NIE TAK NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN...
result:
ok correct (13 test cases)
Test #4:
score: 0
Accepted
time: 826ms
memory: 96064kb
input:
4 1000000 1000000 883198 803418 803418 883198 883198 803418 803418 883198 883198 803418 803418 883198 803418 883198 883198 803418 883198 803418 883198 803418 883198 803418 883198 803418 803418 883198 883198 803418 803418 883198 803418 883198 883198 803418 883198 803418 883198 803418 803418 883198 88...
output:
NIE NIE NIE NIE
result:
ok correct (4 test cases)
Test #5:
score: 0
Accepted
time: 1713ms
memory: 102488kb
input:
4 1000000 1000000 820179 264070 64152 264070 264070 865675 614523 264070 264070 701152 609404 264070 793293 264070 264070 809556 467741 643260 337227 264070 264070 445071 248826 822649 856028 128336 367537 264070 81341 264070 476352 687682 306818 264070 123295 410991 255671 264070 61947 264070 24372...
output:
TAK NNNNTNNNNNTNNNNNNNNNNNTNTNNTNNNTNNTNNNTNTTTNNNNNTNNNNNNTNTTNNNTNNNTTTNTNNNNNTNNNNNTNTTNNTNNNTTTTNTNNNTNNTTTTNNTNTNNNNTTNTNTTTTNNNNNNNTNTNNNNTNNNNTTTNNNNNNTNTNNNNNTTNTTNNTNNNNTNTNTNNTTTNNTNNTNTNNTTNTNNNNNNNTNNNNTTNNNNNNNNNTNNTNNNTTNNTTNNTNNTNNNNTNNNTNTNNTTNNNNNTNNNNNNNTNTNNNTNTNNNNNNNTNNNNNTNTNNT...
result:
ok correct (4 test cases)
Test #6:
score: 0
Accepted
time: 1090ms
memory: 99684kb
input:
4 1000000 1000000 744622 299781 744622 837726 883242 744622 672533 744622 744622 685446 942503 744622 677083 744622 744622 624546 744622 586007 193995 744622 744622 276667 744622 733596 744622 458621 744622 685762 232706 744622 744622 460264 744622 683335 744622 708865 744622 893299 744622 254173 31...
output:
TAK TTNNTNNTTNTTTTNTTTTTNTTTTTNTTTNTNTTTTNTTTTTTTTTNNTTTTNTNNTTTTTTTTTTTNTTTTTTTTTTTNTNTTTNTTTTTTTTTTTTTTNNTNTNTTNTTTTTTNTTTTNTNTTNTTTTTTTTTTTTTNTTTTTTTNTTTTTTNTTNTTTNTTTTTTTTTNNTTTTTTTNTTTNTTTTTTTTNNNNTTTTTTTTTTTTTNNTTTTTTTTTNTTTNNTTNNTTTTTTTTTTTTTNTTTTTTTTTNTTTTTNTTTTTTTNNTTTTTTTTTTTTTNTTTTTTTNTNT...
result:
ok correct (4 test cases)