QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#524313#8011. Institutemisaka18931WA 2ms20128kbC++141.5kb2024-08-19 15:31:072024-08-19 15:31:07

Judging History

This is the latest submission verdict.

  • [2024-08-19 15:31:07]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 20128kb
  • [2024-08-19 15:31:07]
  • Submitted

answer

#include <bits/stdc++.h>
#include <cstdint>
using namespace std;
const int N = 3e5+5, M = 2e6;

int dfn[N], low[N], dfncnt, s[N], in_stack[N], tp;
int scc[N], sc;  // 结点 i 所在 SCC 的编号
int sz[N];       // 强连通 i 的大小

vector<int> g[N], g1[N];

void tarjan(int u) {
  low[u] = dfn[u] = ++dfncnt, s[++tp] = u, in_stack[u] = 1;
  for (auto v : g1[u]) {
    if (!dfn[v]) {
      tarjan(v);
      low[u] = min(low[u], low[v]);
    } else if (in_stack[v]) {
      low[u] = min(low[u], dfn[v]);
    }
  }
  if (dfn[u] == low[u]) {
    ++sc;
    while (s[tp] != u) {
      scc[s[tp]] = sc;
      sz[sc]++;
      in_stack[s[tp]] = 0;
      --tp;
    }
    scc[s[tp]] = sc;
    sz[sc]++;
    in_stack[s[tp]] = 0;
    --tp;
  }
}

vector<pair<int,int>> edges;
bool vis[N], v2[N];

void dfs(int u) {
    vis[u] = 1;
    for (auto v : g[u]) if (!vis[v])
        dfs(v);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int u, v, t;
        cin >> u >> v >> t;
        g[u].push_back(v);
        if (t == 2) {
            g1[u].push_back(v);
            edges.push_back({u,v});
        }
    }
    for (int i = 1; i <= n; ++i) if (!dfn[i]) tarjan(i);
    dfs(1);
    for (auto [u, v] : edges) {
        if (scc[u] != scc[v]) v2[u] = 1;
    }
    bool ans = 0;
    for (int i = 1; i <= n; ++i) if (vis[i] && v2[scc[i]]) ans = 1;
    cout << (ans?"Yes":"No") << '\n';
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 20128kb

input:

3 4
1 2 1
2 3 2
3 2 1
3 1 2

output:

Yes

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 0ms
memory: 19228kb

input:

6 8
1 2 1
2 3 2
3 2 2
3 4 1
4 1 2
1 5 2
5 4 2
6 1 2

output:

No

result:

ok answer is NO

Test #3:

score: 0
Accepted
time: 0ms
memory: 19292kb

input:

1000 1000
141 466 1
634 659 1
179 96 2
445 344 2
993 974 1
310 114 2
32 333 1
758 832 1
834 1 1
874 825 2
480 61 2
765 100 2
804 616 1
496 545 1
786 261 2
899 263 1
962 237 2
766 807 1
561 583 1
35 425 1
201 291 1
6 142 1
61 386 2
785 861 2
386 986 2
288 769 2
850 209 1
660 259 2
258 143 2
646 715 2...

output:

Yes

result:

ok answer is YES

Test #4:

score: 0
Accepted
time: 2ms
memory: 19604kb

input:

1000 3000
719 279 2
857 23 1
984 625 2
904 509 2
892 456 2
589 195 2
718 932 2
608 363 1
474 672 1
217 993 2
165 895 2
727 329 2
932 404 2
952 146 2
201 272 2
412 895 2
228 267 2
396 365 2
813 794 2
259 250 1
968 764 2
100 76 2
924 665 2
981 931 2
292 975 2
903 649 2
793 101 2
54 703 1
853 58 2
356 ...

output:

Yes

result:

ok answer is YES

Test #5:

score: -100
Wrong Answer
time: 2ms
memory: 18944kb

input:

1000 3000
686 470 2
132 418 2
775 962 2
814 8 2
450 767 2
580 243 2
742 534 2
508 304 2
396 513 2
731 385 2
499 309 2
144 150 2
111 209 2
340 189 1
219 755 2
511 655 2
428 941 2
165 707 2
253 619 2
140 766 2
999 132 2
415 101 2
887 192 2
598 262 2
312 675 1
97 527 2
407 179 2
11 154 1
107 996 2
586 ...

output:

Yes

result:

wrong answer expected NO, found YES