QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#815095 | #8921. Интерактивные переходы | ucup-team004 | 0 | 51ms | 12780kb | C++23 | 1.8kb | 2024-12-15 03:45:17 | 2024-12-15 03:45:17 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;
void solve() {
int n, m;
std::cin >> n >> m;
std::vector<int> a(m), b(m), c(m);
for (int i = 0; i < m; i++) {
std::cin >> a[i] >> b[i] >> c[i];
a[i]--;
b[i]--;
}
std::vector<int> d(n);
for (int i = 0; i < n; i++) {
std::cin >> d[i];
}
std::vector<std::array<int, 2>> ans;
for (int i = 0; i < n; i++) {
if (d[i] == 0) {
ans.push_back({i + 1, 1});
}
}
std::vector<std::vector<int>> adj(n);
std::vector<int> deg(n);
for (int i = 0; i < m; i++) {
if (d[a[i]] != d[b[i]]) {
if (c[i] == d[a[i]]) {
adj[a[i]].push_back(b[i]);
deg[b[i]]++;
} else {
adj[b[i]].push_back(a[i]);
deg[a[i]]++;
}
}
}
std::vector<int> q;
for (int i = 0; i < n; i++) {
if (deg[i] == 0) {
q.push_back(i);
}
}
for (int i = 0; i < q.size(); i++) {
int x = q[i];
for (auto y : adj[x]) {
if (--deg[y] == 0) {
q.push_back(y);
}
}
}
if (q.size() != n) {
std::cout << "NO\n";
return;
}
for (auto i : q) {
ans.push_back({i, d[i]});
}
std::cout << "YES\n";
std::cout << ans.size() << "\n";
for (auto [x, y] : ans) {
std::cout << x << " " << y << "\n";
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3820kb
input:
230 1 0 0 1 0 1 2 0 0 0 2 0 1 0 2 0 0 1 2 0 1 1 2 1 1 2 1 0 0 2 1 1 2 1 1 0 2 1 1 2 1 0 1 2 1 1 2 1 1 1 2 1 1 2 0 0 0 2 1 1 2 0 1 0 2 1 1 2 0 0 1 2 1 1 2 0 1 1 3 0 0 0 0 3 0 1 0 0 3 0 0 1 0 3 0 1 1 0 3 0 0 0 1 3 0 1 0 1 3 0 0 1 1 3 0 1 1 1 3 1 1 2 1 0 0 0 3 1 1 2 1 1 0 0 3 1 1 2 1 0 1 0 3 1 1 2 1 1 ...
output:
YES 2 1 1 0 0 YES 1 0 1 YES 4 1 1 2 1 0 0 1 0 YES 3 2 1 0 1 1 0 YES 3 1 1 0 0 1 1 YES 2 0 1 1 1 YES 4 1 1 2 1 0 0 1 0 YES 3 2 1 0 1 1 0 YES 3 1 1 1 1 0 0 YES 2 0 1 1 1 YES 4 1 1 2 1 0 0 1 0 YES 3 2 1 1 0 0 1 YES 3 1 1 0 0 1 1 YES 2 0 1 1 1 YES 6 1 1 2 1 3 1 0 0 1 0 2 0 YES 5 2 1 3 1 0 1 1 0 2 0 YES ...
result:
wrong answer Integer parameter [name=v[2]] equals to 0, violates the range [1, 1] (test case 1)
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 3628kb
input:
222 5 9 1 2 1 2 4 1 3 5 0 4 5 1 2 3 0 3 4 0 1 3 0 2 5 1 1 4 1 1 0 0 1 1 5 9 2 5 0 1 2 0 2 3 0 1 4 0 3 5 1 3 4 0 2 4 0 1 5 0 1 3 0 0 0 1 0 0 5 9 3 4 0 1 2 0 3 5 1 2 4 0 1 3 0 2 5 0 2 3 0 1 4 0 4 5 1 0 0 0 0 1 5 9 3 5 0 2 3 0 1 2 0 3 4 0 1 3 0 2 4 1 4 5 1 1 5 0 2 5 0 0 0 0 1 0 5 9 1 3 0 2 4 1 1 2 0 4 ...
output:
YES 7 2 1 3 1 2 0 4 1 3 1 0 1 1 0 YES 9 1 1 2 1 4 1 5 1 0 0 1 0 3 0 2 1 4 0 YES 9 1 1 2 1 3 1 4 1 0 0 1 0 4 1 2 0 3 0 YES 9 1 1 2 1 3 1 5 1 0 0 2 0 3 1 1 0 4 0 YES 7 1 1 5 1 0 0 3 1 4 0 2 1 1 1 YES 7 3 1 5 1 2 0 4 0 3 1 1 1 0 1 YES 7 3 1 5 1 1 1 3 1 4 0 2 0 0 1 YES 7 1 1 5 1 1 1 2 1 4 0 0 0 3 1 YES ...
result:
wrong answer Integer parameter [name=v[6]] equals to 0, violates the range [1, 5] (test case 1)
Subtask #3:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 23ms
memory: 3608kb
input:
4000 20 25 14 18 1 14 16 1 2 18 1 2 3 1 11 17 1 4 17 1 10 14 1 2 7 1 11 12 1 6 8 1 15 20 1 6 17 1 7 8 1 7 9 1 7 16 1 17 19 1 1 17 1 12 17 1 2 17 1 11 20 1 3 8 1 11 19 1 5 14 1 2 13 1 3 16 1 1 1 0 1 1 1 1 1 0 1 1 0 0 0 1 1 1 1 1 1 20 25 3 15 1 12 17 1 5 12 1 9 14 1 15 17 1 9 10 1 5 14 1 7 20 1 10 18 ...
output:
YES 25 3 1 9 1 12 1 13 1 14 1 0 1 1 1 3 1 4 1 5 1 6 1 7 1 9 1 10 1 14 1 15 1 16 1 17 1 18 1 19 1 12 0 8 0 2 0 11 0 13 0 YES 28 1 1 2 1 3 1 5 1 11 1 13 1 18 1 20 1 0 0 3 1 5 1 6 1 7 1 8 1 9 1 11 1 13 1 14 1 15 1 16 1 18 1 12 0 1 0 17 0 19 0 2 0 10 0 4 0 YES 27 4 1 8 1 9 1 10 1 11 1 12 1 20 1 0 1 1 1 ...
result:
wrong answer Integer parameter [name=v[6]] equals to 0, violates the range [1, 20] (test case 1)
Subtask #4:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 32ms
memory: 3836kb
input:
10000 10 9 1 2 0 1 3 0 1 4 0 1 5 0 1 6 0 1 7 0 1 8 0 1 9 0 1 10 0 0 0 0 0 0 0 1 1 0 0 10 9 1 2 1 1 3 0 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 0 1 1 0 0 1 1 1 0 1 0 10 9 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 1 0 0 0 1 1 0 0 1 0 10 9 1 2 0 1 3 0 1 4 1 1 5 1 1 6 0 1 7 1 1 8 1 1 9 1 1...
output:
YES 18 1 1 2 1 3 1 4 1 5 1 6 1 9 1 10 1 0 0 1 0 2 0 3 0 4 0 5 0 8 0 9 0 6 1 7 1 YES 14 3 1 4 1 8 1 10 1 1 1 2 0 4 1 5 1 6 1 8 1 9 0 0 1 3 0 7 0 YES 16 2 1 3 1 4 1 7 1 8 1 10 1 0 1 4 1 5 1 8 1 1 0 2 0 3 0 6 0 7 0 9 0 YES 14 1 1 2 1 3 1 6 1 1 0 2 0 3 1 4 1 5 0 6 1 7 1 8 1 9 1 0 0 YES 12 8 1 10 1 1 1 2...
result:
wrong answer Integer parameter [name=v[9]] equals to 0, violates the range [1, 10] (test case 1)
Subtask #5:
score: 0
Wrong Answer
Test #14:
score: 0
Wrong Answer
time: 51ms
memory: 12780kb
input:
1 100000 199997 1 19238 0 1 42340 0 1 50103 0 1 72140 0 1 94374 0 2 918 1 2 30562 1 2 48451 1 2 53070 1 2 77905 1 3 56418 0 3 61803 0 4 19423 0 4 33995 0 4 64168 0 4 83220 0 4 87239 0 5 24531 1 5 45512 1 6 23321 1 6 34013 1 6 36584 1 6 37278 1 7 16740 1 7 23485 1 7 63378 1 7 71568 1 7 80434 1 7 8103...
output:
YES 149880 1 1 3 1 4 1 14 1 16 1 21 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 32 1 36 1 37 1 38 1 40 1 41 1 44 1 46 1 47 1 48 1 49 1 50 1 52 1 54 1 55 1 59 1 60 1 62 1 66 1 67 1 69 1 71 1 72 1 73 1 75 1 76 1 77 1 78 1 79 1 80 1 82 1 84 1 87 1 88 1 91 1 95 1 96 1 100 1 102 1 103 1 105 1 108 1 109 1 113 1 ...
result:
wrong answer Integer parameter [name=v[49881]] equals to 0, violates the range [1, 100000] (test case 1)
Subtask #6:
score: 0
Wrong Answer
Test #22:
score: 0
Wrong Answer
time: 1ms
memory: 3788kb
input:
1 2000 1999 1 2 0 2 3 0 3 4 0 4 5 1 5 6 0 6 7 0 7 8 0 8 9 1 9 10 1 10 11 1 11 12 0 12 13 0 13 14 0 14 15 0 15 16 0 16 17 0 17 18 0 18 19 1 19 20 1 20 21 1 21 22 1 22 23 0 23 24 1 24 25 1 25 26 1 26 27 1 27 28 0 28 29 1 29 30 0 30 31 1 31 32 0 32 33 0 33 34 1 34 35 0 35 36 1 36 37 0 37 38 0 38 39 1 3...
output:
YES 2986 1 1 3 1 4 1 5 1 6 1 7 1 8 1 12 1 13 1 16 1 17 1 18 1 19 1 21 1 22 1 25 1 27 1 28 1 30 1 34 1 37 1 38 1 40 1 44 1 50 1 52 1 54 1 58 1 60 1 64 1 66 1 69 1 70 1 72 1 73 1 76 1 80 1 83 1 84 1 85 1 86 1 88 1 90 1 91 1 92 1 94 1 95 1 97 1 98 1 99 1 101 1 102 1 110 1 111 1 112 1 113 1 117 1 118 1 ...
result:
wrong answer Integer parameter [name=v[987]] equals to 0, violates the range [1, 2000] (test case 1)
Subtask #7:
score: 0
Skipped
Dependency #6:
0%
Subtask #8:
score: 0
Skipped
Dependency #6:
0%
Subtask #9:
score: 0
Skipped
Dependency #4:
0%
Subtask #10:
score: 0
Wrong Answer
Test #50:
score: 6
Accepted
time: 15ms
memory: 10980kb
input:
1 100000 100000 1 2 0 2 3 1 3 4 0 4 5 1 5 6 0 6 7 1 7 8 0 8 9 1 9 10 0 10 11 1 11 12 0 12 13 1 13 14 0 14 15 1 15 16 0 16 17 1 17 18 0 18 19 1 19 20 0 20 21 1 21 22 0 22 23 1 23 24 0 24 25 1 25 26 0 26 27 1 27 28 0 28 29 1 29 30 0 30 31 1 31 32 0 32 33 1 33 34 0 34 35 1 35 36 0 36 37 1 37 38 0 38 39...
output:
NO
result:
ok ok (1 test case)
Test #51:
score: 6
Accepted
time: 15ms
memory: 10964kb
input:
1 100000 100000 1 2 0 2 3 1 3 4 0 4 5 1 5 6 0 6 7 1 7 8 0 8 9 1 9 10 0 10 11 1 11 12 0 12 13 1 13 14 0 14 15 1 15 16 0 16 17 1 17 18 0 18 19 1 19 20 0 20 21 1 21 22 0 22 23 1 23 24 0 24 25 1 25 26 0 26 27 1 27 28 0 28 29 1 29 30 0 30 31 1 31 32 0 32 33 1 33 34 0 34 35 1 35 36 0 36 37 1 37 38 0 38 39...
output:
NO
result:
ok ok (1 test case)
Test #52:
score: 6
Accepted
time: 15ms
memory: 11120kb
input:
1 100000 100000 1 2 1 2 3 0 3 4 1 4 5 0 5 6 1 6 7 0 7 8 1 8 9 0 9 10 1 10 11 0 11 12 1 12 13 0 13 14 1 14 15 0 15 16 1 16 17 0 17 18 1 18 19 0 19 20 1 20 21 0 21 22 1 22 23 0 23 24 1 24 25 0 25 26 1 26 27 0 27 28 1 28 29 0 29 30 1 30 31 0 31 32 1 32 33 0 33 34 1 34 35 0 35 36 1 36 37 0 37 38 1 38 39...
output:
NO
result:
ok ok (1 test case)
Test #53:
score: 6
Accepted
time: 15ms
memory: 10948kb
input:
1 100000 100000 1 2 1 2 3 0 3 4 1 4 5 0 5 6 1 6 7 0 7 8 1 8 9 0 9 10 1 10 11 0 11 12 1 12 13 0 13 14 1 14 15 0 15 16 1 16 17 0 17 18 1 18 19 0 19 20 1 20 21 0 21 22 1 22 23 0 23 24 1 24 25 0 25 26 1 26 27 0 27 28 1 28 29 0 29 30 1 30 31 0 31 32 1 32 33 0 33 34 1 34 35 0 35 36 1 36 37 0 37 38 1 38 39...
output:
NO
result:
ok ok (1 test case)
Test #54:
score: 0
Wrong Answer
time: 28ms
memory: 11312kb
input:
1 100000 100000 1 2 1 2 3 0 3 4 0 4 5 0 5 6 1 6 7 1 7 8 0 8 9 1 9 10 1 10 11 0 11 12 1 12 13 0 13 14 0 14 15 0 15 16 1 16 17 1 17 18 0 18 19 1 19 20 1 20 21 0 21 22 1 22 23 0 23 24 1 24 25 1 25 26 1 26 27 0 27 28 0 28 29 1 29 30 1 30 31 0 31 32 1 32 33 1 33 34 1 34 35 0 35 36 1 36 37 1 37 38 0 38 39...
output:
YES 149854 2 1 6 1 12 1 15 1 19 1 21 1 22 1 24 1 27 1 28 1 29 1 30 1 31 1 34 1 35 1 37 1 41 1 44 1 47 1 48 1 49 1 57 1 58 1 60 1 62 1 63 1 64 1 66 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 76 1 77 1 84 1 85 1 86 1 88 1 89 1 90 1 91 1 94 1 98 1 99 1 100 1 101 1 103 1 106 1 109 1 110 1 113 1 114 1 119 1 12...
result:
wrong answer Integer parameter [name=v[49855]] equals to 0, violates the range [1, 100000] (test case 1)
Subtask #11:
score: 0
Skipped
Dependency #2:
0%
Subtask #12:
score: 0
Skipped
Dependency #1:
0%