QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#150611#5511. Minor EvilahsoltanAC ✓1629ms66804kbC++171.4kb2023-08-25 21:45:372023-08-25 21:45:39

Judging History

你现在查看的是最新测评结果

  • [2023-08-25 21:45:39]
  • 评测
  • 测评结果:AC
  • 用时:1629ms
  • 内存:66804kb
  • [2023-08-25 21:45:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 2137
#endif

const int INF = 1e9;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
  cin >> tt;
  while (tt--) {
    int n, k;
    cin >> n >> k;
    vector<vector<pair<int, int>>> adj(n);
    for (int i = 0; i < k; i++) {
      int u, v;
      cin >> u >> v;
      u--; v--;
      adj[u].push_back({v, i});
    }
    int s;
    cin >> s;
    vector<bool> a(n);
    for (int i = 0; i < s; i++) {
      int u;
      cin >> u;
      a[u - 1] = true;
    }
    priority_queue<pair<int, int>> q;
    vector<int> dst(n, -1);
    for (int i = 0; i < n; i++) {
      if (!a[i]) {
        dst[i] = INF;
        q.push({dst[i], i});
      }
    }
    while (!q.empty()) {
      auto [d, u] = q.top();
      q.pop();
      if (d != dst[u]) {
        continue;
      }
      for (auto [v, i] : adj[u]) {
        if (i < dst[u] && i > dst[v]) {
          dst[v] = i;
          q.push({dst[v], v});
        }
      }
    }
    bool ok = true;
    string ans(k, 'N');
    for (int i = 0; i < n; i++) {
      if (a[i] && dst[i] == -1) {
        ok = false;
        break;
      } else if (a[i]) {
        ans[dst[i]] = 'T';
      }
    }
    if (ok) {
      cout << "TAK\n" << ans << '\n';
    } else {
      cout << "NIE\n";
    }
  }
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3468kb

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: 655ms
memory: 4624kb

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: 1327ms
memory: 63688kb

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: 740ms
memory: 59088kb

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: 1629ms
memory: 66804kb

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: 1033ms
memory: 65204kb

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)