QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#304776 | #8011. Institute | ucup-team992# | WA | 1ms | 3832kb | C++11 | 1.8kb | 2024-01-14 02:45:44 | 2024-01-14 02:45:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef int uci;
#define int long long
#define ll long long
#define F first
#define S second
#define ar array
vector<vector<pair<ll,ll>>> adj;
vector<ll> val, comp, z, cont;
ll T, ncomps;
ll dfs(ll j) {
int lo = val[j] = ++T, x; z.push_back(j);
for(auto e: adj[j]) {
if(e.S != 2) continue;
if(comp[e.F] < 0) lo = min(lo, val[e.F] ?: dfs(e.F));
}
if(lo == val[j]) {
do {
x = z.back(); z.pop_back();
comp[x] = ncomps;
cont.push_back(x);
} while(x != j);
cont.clear();
ncomps++;
}
return val[j] = lo;
}
void solve(){
ll N, M;
cin >> N >> M;
adj = vector<vector<pair<ll,ll>>>(N);
for(int i = 0; i < M; i++) {
ll u,v,t;
cin >> u >> v >> t;
u--;
v--;
adj[u].push_back({v,t});
}
// condition: does there exist a reachable node such that it has a 1-edge going somewhere else but no 1-cycle going to it.
vector<ll> vis;
vector<bool> seen(N, false);
vector<ll> vq; vq.push_back(0);
while(vq.size()) {
ll n = vq.back(); vq.pop_back();
if(seen[n]) continue;
vis.push_back(n); seen[n] = true;
for(auto a: adj[n]) vq.push_back(a.S);
}
val.assign(N,0); comp.assign(N,-1);T=ncomps=0;
for(int i = 0; i < N; i++) if(comp[i] < 0) dfs(i);
bool c = false;
for(auto v: vis) {
for(auto a: adj[v]) {
if(a.S != 2) continue;
//cout << v << " " << a.F << std::endl;
c = c || (comp[a.F] != comp[v]);
}
}
if(c) cout << "Yes\n";
else cout << "No\n";
}
uci main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3828kb
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: 1ms
memory: 3832kb
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: 1ms
memory: 3828kb
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: -100
Wrong Answer
time: 0ms
memory: 3680kb
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:
No
result:
wrong answer expected YES, found NO