QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#307346 | #8011. Institute | ucup_team_qiuly# | WA | 3ms | 12500kb | C++14 | 1.7kb | 2024-01-18 14:21:21 | 2024-01-18 14:21:22 |
Judging History
answer
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(...) fprintf (stderr, __VA_ARGS__)
#define lep(i, l, r) for (int i = (l), i##_end = (r); i <= i##_end; ++ i)
#define rep(i, r, l) for (int i = (r), i##_end = (l); i >= i##_end; -- i)
char _c; bool _f; template <class T> inline void IN (T & x) {
_f = 0, x = 0; while (_c = getchar (), ! isdigit (_c)) if (_c == '-') _f = 1;
while (isdigit (_c)) x = x * 10 + _c - '0', _c = getchar (); if (_f) x = - x;
}
const int N = 3e5 + 5;
int n, m;
vector <int> to[N];
// tarjan
int tim, dfn[N], low[N], cnt, scc[N];
stack <int> stk;
void tarjan (int u) {
dfn[u] = low[u] = ++ tim, stk.emplace ( u );
for (auto & v : to[u]) {
if (! dfn[v]) tarjan (v), low[u] = min (low[u], low[v]);
else if (! scc[u]) low[u] = min (low[u], dfn[v]);
}
if (low[u] == dfn[u]) {
++ cnt;
for (int x; ; ) {
x = stk.top (), stk.pop ();
if (scc[x] = cnt, x == u) break ;
}
}
}
//
signed main () {
IN (n), IN (m);
vector <pair <int, int> > edge;
for (int u, v, c, i = 1; i <= m; ++ i) {
IN (u), IN (v), IN (c);
if (c == 2) to[u].emplace_back ( v );
else edge.emplace_back ( u, v );
}
lep (i, 1, n) if (! dfn[i]) tarjan (i);
vector <int> out (cnt + 1);
lep (i, 1, n) for (auto & j : to[i]) {
if (scc[i] != scc[j]) out[scc[i]] ++ ;
}
for (auto & [u, v] : edge) {
to[u].emplace_back ( v );
}
vector <int> vis (n + 1);
queue <int> q;
for ( q.emplace ( 1 ), vis[1] = true; ! q.empty (); ) {
int u = q.front (); q.pop ();
for (auto & v : to[u]) {
if (! vis[v]) {
vis[v] = true, q.emplace ( u );
}
}
}
lep (i, 1, n) if (vis[i] && out[scc[i]]) return puts ("Yes"), 0;
return puts ("No"), 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 12308kb
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: 2ms
memory: 11228kb
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: 11288kb
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: 3ms
memory: 11780kb
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: 0
Accepted
time: 3ms
memory: 12500kb
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:
No
result:
ok answer is NO
Test #6:
score: 0
Accepted
time: 3ms
memory: 11932kb
input:
10000 10000 1496 8533 1 6761 8802 2 3147 8733 2 7074 899 1 4191 9520 2 2576 1464 1 8600 116 2 72 5894 1 1605 6769 1 344 2583 2 9951 8053 2 2663 1396 1 3172 7307 1 8490 8085 2 6623 7814 2 680 4471 2 4906 3810 1 5952 8860 1 9670 3644 2 7993 6329 2 4666 1119 2 3115 3676 2 4506 2979 2 1451 2540 2 5002 9...
output:
No
result:
ok answer is NO
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 12100kb
input:
10000 30000 8022 6065 2 8185 3186 1 9803 6371 1 4947 1271 2 926 9103 2 8367 1328 2 6314 1627 2 203 4366 2 9992 1021 2 5092 9288 1 7412 6217 2 4569 5568 2 7064 6970 2 4363 1581 2 772 6243 2 2571 4950 2 5821 8367 1 7985 5827 2 2064 4754 2 900 605 1 2083 3137 2 7852 1194 2 4679 6769 2 9389 6753 2 2980 ...
output:
No
result:
wrong answer expected YES, found NO