QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#335478#6536. LawyersJooDdaeWA 1ms5700kbC++20923b2024-02-23 14:25:262024-02-23 14:25:27

Judging History

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

  • [2024-02-23 14:25:27]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5700kb
  • [2024-02-23 14:25:26]
  • 提交

answer

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

int n, m, x[200200], y[200200], chk[200200], chk2[200200];
vector<int> v[200200];
set<array<int, 2>> s;

array<int, 3> dfs(int u) {
    chk2[u] = 1;
    array<int, 3> re = {1, (int)v[u].size(), chk[u]};
    for(auto x : re) if(!chk2[u]) {
        auto [A, B, C] = dfs(x);
        re[0] += A, re[1] += B, re[2] |= C;
    }
    return re;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    for(int i=1;i<=m;i++) cin >> x[i] >> y[i];
    for(int i=1;i<=m;i++) s.insert({x[i], y[i]});
    for(int i=1;i<=m;i++) {
        if(!s.count({y[i], x[i]})) s.erase({x[i], y[i]}), chk[y[i]] = 1;
        else v[x[i]].push_back(y[i]);
    }

    for(int i=1;i<=n;i++) if(!chk[i] && !chk2[i]) {
        auto [x, y, flag] = dfs(i);
        if(!flag && x == y/2+1) return cout << "NO", 0;
    }
    cout << "YES";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 3
1 2
2 3
3 1

output:

YES

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 1ms
memory: 5696kb

input:

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

output:

NO

result:

ok answer is NO

Test #3:

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

input:

4 4
1 2
2 1
3 4
4 3

output:

NO

result:

ok answer is NO

Test #4:

score: 0
Accepted
time: 1ms
memory: 5580kb

input:

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

output:

NO

result:

ok answer is NO

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 5616kb

input:

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

output:

NO

result:

wrong answer expected YES, found NO