#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define mp make_pair
#define f first
#define s second
multiset<pii> edges[60005];
bitset<1200001> pos;
int bal;
void dfs(int x, int c) {
if (!edges[x].empty()) {
pii cur = *edges[x].begin();
edges[x].clear();
edges[cur.f].erase(edges[cur.f].find(mp(x, cur.s)));
bal += c*cur.s;
dfs(cur.f, -c);
}
}
int main() {
int n, k, x, y, z, balance = 600000;
scanf("%d%d", &n, &k);
for (int i=1; i<=2*n; i++) {
scanf("%d%d%d", &x, &y, &z);
y += n;
edges[x].insert(mp(y, z));
edges[y].insert(mp(x, z));
}
vector<int> forced;
for (int i=1; i<=2*n; i++) {
if (edges[i].empty()) {
printf("NO\n");
return 0;
}
if (edges[i].size() == 1) forced.push_back(i);
}
while (!forced.empty()) {
int cur = forced.back();
forced.pop_back();
pii x = *edges[cur].begin();
edges[cur].clear();
if (cur <= n) balance += x.s;
else balance -= x.s;
edges[x.f].erase(edges[x.f].find(mp(cur, x.s)));
if (edges[x.f].size() == 1) forced.push_back(x.f);
}
pos.set(balance);
for (int i=1; i<=2*n; i++) {
if (!edges[i].empty()) {
pii cur = *edges[i].begin();
edges[i].erase(edges[i].find(cur));
edges[cur.f].erase(edges[cur.f].find(mp(i, cur.s)));
bal = cur.s;
dfs(i, -1);
//printf("Test: %d\n", bal);
bal = abs(bal);
pos = (pos << bal) | (pos >> bal);
}
}
for (int i=-k; i<=k; i++) {
if (0 <= 600000+i && 600000+i < 1200001 && pos[600000+i]) {
printf("YES\n");
return 0;
}
}
printf("NO\n");
}
Compilation message
tug.cpp: In function 'int main()':
tug.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
tug.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | scanf("%d%d%d", &x, &y, &z);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3668 KB |
Output is correct |
2 |
Correct |
2 ms |
3700 KB |
Output is correct |
3 |
Correct |
2 ms |
3668 KB |
Output is correct |
4 |
Correct |
3 ms |
3696 KB |
Output is correct |
5 |
Correct |
2 ms |
3692 KB |
Output is correct |
6 |
Correct |
2 ms |
3668 KB |
Output is correct |
7 |
Correct |
3 ms |
3668 KB |
Output is correct |
8 |
Correct |
3 ms |
3668 KB |
Output is correct |
9 |
Correct |
2 ms |
3668 KB |
Output is correct |
10 |
Correct |
2 ms |
3668 KB |
Output is correct |
11 |
Correct |
2 ms |
3668 KB |
Output is correct |
12 |
Correct |
3 ms |
3668 KB |
Output is correct |
13 |
Correct |
3 ms |
3692 KB |
Output is correct |
14 |
Correct |
3 ms |
3668 KB |
Output is correct |
15 |
Correct |
3 ms |
3668 KB |
Output is correct |
16 |
Correct |
2 ms |
3668 KB |
Output is correct |
17 |
Correct |
2 ms |
3668 KB |
Output is correct |
18 |
Correct |
2 ms |
3668 KB |
Output is correct |
19 |
Correct |
3 ms |
3668 KB |
Output is correct |
20 |
Correct |
3 ms |
3668 KB |
Output is correct |
21 |
Correct |
2 ms |
3540 KB |
Output is correct |
22 |
Correct |
3 ms |
3696 KB |
Output is correct |
23 |
Correct |
2 ms |
3668 KB |
Output is correct |
24 |
Correct |
3 ms |
3696 KB |
Output is correct |
25 |
Correct |
2 ms |
3668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3668 KB |
Output is correct |
2 |
Correct |
2 ms |
3700 KB |
Output is correct |
3 |
Correct |
2 ms |
3668 KB |
Output is correct |
4 |
Correct |
3 ms |
3696 KB |
Output is correct |
5 |
Correct |
2 ms |
3692 KB |
Output is correct |
6 |
Correct |
2 ms |
3668 KB |
Output is correct |
7 |
Correct |
3 ms |
3668 KB |
Output is correct |
8 |
Correct |
3 ms |
3668 KB |
Output is correct |
9 |
Correct |
2 ms |
3668 KB |
Output is correct |
10 |
Correct |
2 ms |
3668 KB |
Output is correct |
11 |
Correct |
2 ms |
3668 KB |
Output is correct |
12 |
Correct |
3 ms |
3668 KB |
Output is correct |
13 |
Correct |
3 ms |
3692 KB |
Output is correct |
14 |
Correct |
3 ms |
3668 KB |
Output is correct |
15 |
Correct |
3 ms |
3668 KB |
Output is correct |
16 |
Correct |
2 ms |
3668 KB |
Output is correct |
17 |
Correct |
2 ms |
3668 KB |
Output is correct |
18 |
Correct |
2 ms |
3668 KB |
Output is correct |
19 |
Correct |
3 ms |
3668 KB |
Output is correct |
20 |
Correct |
3 ms |
3668 KB |
Output is correct |
21 |
Correct |
2 ms |
3540 KB |
Output is correct |
22 |
Correct |
3 ms |
3696 KB |
Output is correct |
23 |
Correct |
2 ms |
3668 KB |
Output is correct |
24 |
Correct |
3 ms |
3696 KB |
Output is correct |
25 |
Correct |
2 ms |
3668 KB |
Output is correct |
26 |
Correct |
132 ms |
4108 KB |
Output is correct |
27 |
Correct |
20 ms |
4052 KB |
Output is correct |
28 |
Correct |
150 ms |
4100 KB |
Output is correct |
29 |
Correct |
20 ms |
4088 KB |
Output is correct |
30 |
Correct |
140 ms |
4116 KB |
Output is correct |
31 |
Correct |
20 ms |
4136 KB |
Output is correct |
32 |
Correct |
126 ms |
4108 KB |
Output is correct |
33 |
Correct |
20 ms |
4052 KB |
Output is correct |
34 |
Correct |
15 ms |
4116 KB |
Output is correct |
35 |
Correct |
23 ms |
4052 KB |
Output is correct |
36 |
Correct |
140 ms |
4112 KB |
Output is correct |
37 |
Correct |
20 ms |
4052 KB |
Output is correct |
38 |
Correct |
140 ms |
4112 KB |
Output is correct |
39 |
Correct |
20 ms |
4096 KB |
Output is correct |
40 |
Correct |
132 ms |
4092 KB |
Output is correct |
41 |
Correct |
20 ms |
4100 KB |
Output is correct |
42 |
Correct |
147 ms |
4116 KB |
Output is correct |
43 |
Correct |
20 ms |
4052 KB |
Output is correct |
44 |
Correct |
136 ms |
4104 KB |
Output is correct |
45 |
Correct |
20 ms |
4052 KB |
Output is correct |
46 |
Correct |
129 ms |
4108 KB |
Output is correct |
47 |
Correct |
4 ms |
3924 KB |
Output is correct |
48 |
Correct |
63 ms |
4052 KB |
Output is correct |
49 |
Correct |
64 ms |
4052 KB |
Output is correct |
50 |
Correct |
152 ms |
4112 KB |
Output is correct |
51 |
Correct |
146 ms |
4052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
427 ms |
5792 KB |
Output is correct |
2 |
Correct |
10 ms |
5628 KB |
Output is correct |
3 |
Correct |
428 ms |
5836 KB |
Output is correct |
4 |
Correct |
10 ms |
5588 KB |
Output is correct |
5 |
Correct |
420 ms |
5796 KB |
Output is correct |
6 |
Correct |
11 ms |
5588 KB |
Output is correct |
7 |
Correct |
346 ms |
5796 KB |
Output is correct |
8 |
Correct |
11 ms |
5580 KB |
Output is correct |
9 |
Correct |
365 ms |
5716 KB |
Output is correct |
10 |
Correct |
14 ms |
5680 KB |
Output is correct |
11 |
Correct |
424 ms |
5716 KB |
Output is correct |
12 |
Correct |
11 ms |
5580 KB |
Output is correct |
13 |
Correct |
407 ms |
5796 KB |
Output is correct |
14 |
Correct |
425 ms |
5716 KB |
Output is correct |
15 |
Correct |
10 ms |
5588 KB |
Output is correct |
16 |
Correct |
343 ms |
5800 KB |
Output is correct |
17 |
Correct |
11 ms |
5656 KB |
Output is correct |
18 |
Correct |
435 ms |
5792 KB |
Output is correct |
19 |
Correct |
11 ms |
5588 KB |
Output is correct |
20 |
Correct |
383 ms |
5800 KB |
Output is correct |
21 |
Correct |
11 ms |
5632 KB |
Output is correct |
22 |
Correct |
218 ms |
5856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3668 KB |
Output is correct |
2 |
Correct |
2 ms |
3700 KB |
Output is correct |
3 |
Correct |
2 ms |
3668 KB |
Output is correct |
4 |
Correct |
3 ms |
3696 KB |
Output is correct |
5 |
Correct |
2 ms |
3692 KB |
Output is correct |
6 |
Correct |
2 ms |
3668 KB |
Output is correct |
7 |
Correct |
3 ms |
3668 KB |
Output is correct |
8 |
Correct |
3 ms |
3668 KB |
Output is correct |
9 |
Correct |
2 ms |
3668 KB |
Output is correct |
10 |
Correct |
2 ms |
3668 KB |
Output is correct |
11 |
Correct |
2 ms |
3668 KB |
Output is correct |
12 |
Correct |
3 ms |
3668 KB |
Output is correct |
13 |
Correct |
3 ms |
3692 KB |
Output is correct |
14 |
Correct |
3 ms |
3668 KB |
Output is correct |
15 |
Correct |
3 ms |
3668 KB |
Output is correct |
16 |
Correct |
2 ms |
3668 KB |
Output is correct |
17 |
Correct |
2 ms |
3668 KB |
Output is correct |
18 |
Correct |
2 ms |
3668 KB |
Output is correct |
19 |
Correct |
3 ms |
3668 KB |
Output is correct |
20 |
Correct |
3 ms |
3668 KB |
Output is correct |
21 |
Correct |
2 ms |
3540 KB |
Output is correct |
22 |
Correct |
3 ms |
3696 KB |
Output is correct |
23 |
Correct |
2 ms |
3668 KB |
Output is correct |
24 |
Correct |
3 ms |
3696 KB |
Output is correct |
25 |
Correct |
2 ms |
3668 KB |
Output is correct |
26 |
Correct |
132 ms |
4108 KB |
Output is correct |
27 |
Correct |
20 ms |
4052 KB |
Output is correct |
28 |
Correct |
150 ms |
4100 KB |
Output is correct |
29 |
Correct |
20 ms |
4088 KB |
Output is correct |
30 |
Correct |
140 ms |
4116 KB |
Output is correct |
31 |
Correct |
20 ms |
4136 KB |
Output is correct |
32 |
Correct |
126 ms |
4108 KB |
Output is correct |
33 |
Correct |
20 ms |
4052 KB |
Output is correct |
34 |
Correct |
15 ms |
4116 KB |
Output is correct |
35 |
Correct |
23 ms |
4052 KB |
Output is correct |
36 |
Correct |
140 ms |
4112 KB |
Output is correct |
37 |
Correct |
20 ms |
4052 KB |
Output is correct |
38 |
Correct |
140 ms |
4112 KB |
Output is correct |
39 |
Correct |
20 ms |
4096 KB |
Output is correct |
40 |
Correct |
132 ms |
4092 KB |
Output is correct |
41 |
Correct |
20 ms |
4100 KB |
Output is correct |
42 |
Correct |
147 ms |
4116 KB |
Output is correct |
43 |
Correct |
20 ms |
4052 KB |
Output is correct |
44 |
Correct |
136 ms |
4104 KB |
Output is correct |
45 |
Correct |
20 ms |
4052 KB |
Output is correct |
46 |
Correct |
129 ms |
4108 KB |
Output is correct |
47 |
Correct |
4 ms |
3924 KB |
Output is correct |
48 |
Correct |
63 ms |
4052 KB |
Output is correct |
49 |
Correct |
64 ms |
4052 KB |
Output is correct |
50 |
Correct |
152 ms |
4112 KB |
Output is correct |
51 |
Correct |
146 ms |
4052 KB |
Output is correct |
52 |
Correct |
427 ms |
5792 KB |
Output is correct |
53 |
Correct |
10 ms |
5628 KB |
Output is correct |
54 |
Correct |
428 ms |
5836 KB |
Output is correct |
55 |
Correct |
10 ms |
5588 KB |
Output is correct |
56 |
Correct |
420 ms |
5796 KB |
Output is correct |
57 |
Correct |
11 ms |
5588 KB |
Output is correct |
58 |
Correct |
346 ms |
5796 KB |
Output is correct |
59 |
Correct |
11 ms |
5580 KB |
Output is correct |
60 |
Correct |
365 ms |
5716 KB |
Output is correct |
61 |
Correct |
14 ms |
5680 KB |
Output is correct |
62 |
Correct |
424 ms |
5716 KB |
Output is correct |
63 |
Correct |
11 ms |
5580 KB |
Output is correct |
64 |
Correct |
407 ms |
5796 KB |
Output is correct |
65 |
Correct |
425 ms |
5716 KB |
Output is correct |
66 |
Correct |
10 ms |
5588 KB |
Output is correct |
67 |
Correct |
343 ms |
5800 KB |
Output is correct |
68 |
Correct |
11 ms |
5656 KB |
Output is correct |
69 |
Correct |
435 ms |
5792 KB |
Output is correct |
70 |
Correct |
11 ms |
5588 KB |
Output is correct |
71 |
Correct |
383 ms |
5800 KB |
Output is correct |
72 |
Correct |
11 ms |
5632 KB |
Output is correct |
73 |
Correct |
218 ms |
5856 KB |
Output is correct |
74 |
Correct |
2061 ms |
10128 KB |
Output is correct |
75 |
Correct |
107 ms |
10132 KB |
Output is correct |
76 |
Correct |
1950 ms |
10132 KB |
Output is correct |
77 |
Correct |
108 ms |
10060 KB |
Output is correct |
78 |
Correct |
1834 ms |
10128 KB |
Output is correct |
79 |
Correct |
1899 ms |
10136 KB |
Output is correct |
80 |
Correct |
123 ms |
10132 KB |
Output is correct |
81 |
Correct |
124 ms |
10108 KB |
Output is correct |
82 |
Correct |
2027 ms |
10132 KB |
Output is correct |
83 |
Correct |
2001 ms |
10132 KB |
Output is correct |
84 |
Correct |
111 ms |
10128 KB |
Output is correct |
85 |
Correct |
2153 ms |
10136 KB |
Output is correct |
86 |
Correct |
111 ms |
10128 KB |
Output is correct |
87 |
Correct |
2141 ms |
10136 KB |
Output is correct |
88 |
Correct |
107 ms |
10096 KB |
Output is correct |
89 |
Correct |
1830 ms |
10132 KB |
Output is correct |
90 |
Correct |
107 ms |
10108 KB |
Output is correct |
91 |
Correct |
1984 ms |
10136 KB |
Output is correct |
92 |
Correct |
106 ms |
10060 KB |
Output is correct |
93 |
Correct |
1820 ms |
10124 KB |
Output is correct |
94 |
Correct |
34 ms |
10012 KB |
Output is correct |
95 |
Correct |
1016 ms |
10344 KB |
Output is correct |
96 |
Correct |
982 ms |
10228 KB |
Output is correct |
97 |
Correct |
1838 ms |
10132 KB |
Output is correct |
98 |
Correct |
1861 ms |
10128 KB |
Output is correct |