QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#77681 | #5511. Minor Evil | XKError | WA | 4ms | 26884kb | C++ | 2.0kb | 2023-02-15 12:46:15 | 2023-02-15 12:46:18 |
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 26884kb
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:
result:
wrong output format Unexpected end of file - token expected (test case 1)