QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#335479 | #6536. Lawyers | JooDdae | WA | 1ms | 5692kb | C++20 | 900b | 2024-02-23 14:27:04 | 2024-02-23 14:27:04 |
Judging History
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[x]) {
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]})) 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";
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5692kb
input:
3 3 1 2 2 3 3 1
output:
YES
result:
ok answer is YES
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5692kb
input:
4 6 1 2 1 3 1 4 2 3 2 4 3 4
output:
YES
result:
wrong answer expected NO, found YES