QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#77683 | #5511. Minor Evil | XKError | WA | 4ms | 27116kb | C++ | 2.0kb | 2023-02-15 12:46:40 | 2023-02-15 12:46:43 |
Judging History
answer
#include <bits/stdc++.h>
#define maxn 1000005
using namespace std;
int n, k;
int a[maxn];
int b[maxn];
int m;
int s[maxn];
vector<pair<int, int> > g[maxn];
void add(int u, int v, int w) {
// cout<<"ADd:"<<u<<" "<<v<<" "<<w<<endl;
g[u].push_back({v, w});
// g[v].push_back({u, w});
}
int f[maxn];
int res[maxn];
int alv[maxn];
queue<int> q;
int main() {
// freopen("dt.in", "r", stdin);
int T;
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) f[i] = k + 1;
for (int i = 1; i <= k; i++) scanf("%d%d", &a[i], &b[i]);
scanf("%d", &m);
for (int i = 1; i <= m; i++) {
int x;
scanf("%d", &x);
s[x] = 1;
}
for (int i = 1; i <= k; i++) {
if (s[b[i]]) add(a[i], b[i], i);
}
for (int i = 1; i <= n; i++) if (!s[i]) q.push(i);
while (!q.empty()) {
int now = q.front(); q.pop();
for (auto p : g[now]) {
int v = p.first, w = p.second;
// cout<<now<<" "<<f[now]<<" "<<w<<" "<<f[v]<<endl;
if (f[now] > w && (f[v] < w || f[v] == k + 1)) {
f[v] = w;
q.push(v);
}
}
}
bool flg = 1;
for (int i = 1; i <= n; i++) {
if (s[i]) {
// cout<<f[i]<<"@"<<endl;
if (f[i] <= k) res[f[i]] = 1;
else flg = 0;
}
}
if (!flg) {
puts("NIE");
for (int i = 1; i <= k; i++) res[i] = f[i] = s[i] = 0, g[i].clear();
continue;
}
puts("TAK");
for (int i = 1; i <= k; i++) putchar(res[i] ? 'T' : 'N');
puts("");
for (int i = 1; i <= n; i++) alv[i] = 1;
for (int i = 1; i <= k; i++) {
if (res[i]) {
if (alv[a[i]] && alv[b[i]]) alv[b[i]] = 0;
}
}
bool fl = 1;
for (int i = 1; i <= n; i++) fl &= (!s[i] || !alv[i]);
if (!fl) {
printf("%d %d\n", n, k);
for (int i = 1; i <= k; i++) printf("%d %d\n", a[i], b[i]);
printf("%d\n", m);
for (int i = 1; i <= n; i++) if (s[i]) printf("%d ", i);
puts("");
return 0;
}
for (int i = 1; i <= k; i++) res[i] = f[i] = s[i] = 0, g[i].clear();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 26924kb
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: 4ms
memory: 27116kb
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 NIE NIE TA...
result:
wrong answer Contestant didn't find the solution. (test case 53)