QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#797412 | #5511. Minor Evil | Ahoora# | WA | 516ms | 48908kb | C++14 | 2.2kb | 2024-12-02 22:55:28 | 2024-12-02 22:55:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define bug(x) cerr << #x << " = " << x << '\n';
const int N = (int)(1e6) + 100;
int n, K, A[N], B[N], d[N], deg[N], pnt[N], S;
bool bad[N];
vector<pair<int, int>> adj[N];
void clear() {
for (int i = 0; i <= n; i++) {
bad[i] = false;
deg[i] = 0;
d[i] = -1;
pnt[i] = 0;
adj[i].clear();
}
}
void solve() {
cin >> n >> K;
for (int i = 0; i < K; i++) {
cin >> A[i] >> B[i];
--A[i], --B[i];
}
cin >> S;
for (int i = 0, v; i < S; i++) {
cin >> v;
--v;
bad[v] = true;
}
fill(d, d + n, -1);
set<pair<int, int>> q;
for (int i = 0; i < K; i++) {
if (!bad[B[i]])
continue;
if (!bad[A[i]]) {
adj[B[i]].push_back({B[i], i});
deg[B[i]]++;
d[B[i]] = i;
q.insert({i, B[i]});
} else {
adj[A[i]].push_back({B[i], i});
deg[A[i]]++;
}
}
for (int i = 0; i < n; i++) {
pnt[i] = 0;
sort(adj[i].begin(), adj[i].end(), [](pair<int, int> x, pair<int, int> y) {
return x.second < y.second;
});
}
while (!q.empty()) {
auto [dd, v] = *(--q.end());
q.erase(--q.end());
while (pnt[v] < deg[v] && adj[v][pnt[v]].second < dd) {
pair<int, int> e = adj[v][pnt[v]];
if (d[e.first] < e.second) {
q.erase({e.first, d[e.first]});
d[e.first] = e.second;
q.insert({e.first, d[e.first]});
}
pnt[v]++;
}
}
set<int> who;
for (int i = 0; i < n; i++)
if (bad[i] && d[i] == -1) {
cout << "NIE\n";
clear();
return;
} else {
who.insert(d[i]);
}
cout << "TAK\n";
for (int i = 0; i < K; i++)
if (who.count(i))
cout << "T";
else
cout << "N";
cout << '\n';
clear();
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int Q;
cin >> Q;
while (Q--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 27108kb
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: -100
Wrong Answer
time: 516ms
memory: 48908kb
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:
wrong answer Contestant didn't find the solution. (test case 93)