#undef _GLIBCXX_DEBUG
#pragma GCC optimize("Ofast,inline")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("bmi,bmi2,lzcnt,popcnt")
#pragma GCC target("movbe")
#pragma GCC target("aes,pclmul,rdrnd")
#pragma GCC target("avx,avx2,f16c,fma,sse3,ssse3,sse4.1,sse4.2")
#include<bits/stdc++.h>
#define doi(i) if(!adj[i].size()) {cout << "NO\n";return 0;}if(adj[i].size()<2) {q.push(i);sum+=(i>n/2?1:-1)*((*begin(adj[i])).second);}
#define shift(x) ((x)>0?bt<<(x):bt>>(-x))
using namespace std;
inline int read() {
int v = 0;
int sign = 1;
char c = getchar();
if (c == '-') {
sign = -1;
} else {
v += c - '0';
}
while ((c = getchar()) != EOF && c != ' ' && c != '\n') {
v *= 10; v += c - '0';
}
return v * sign;
}
multiset<pair<int, int>> adj[200100];
queue<int> q;
bool del[200100];
bitset<1200000> bt;
int tot;
void dfs(int n, int N) {
if (del[n]) return;
del[n] = true;
int nxt, cost;
tie(nxt, cost) = *adj[n].begin();
if(nxt>N)
tot += cost;
else
tot-=cost;
if (!del[nxt]) {
adj[nxt].erase(adj[nxt].find({n, cost}));
adj[n].clear();
dfs(nxt, N);
}
}
int main() {
int n(read()), k(read()), sum = 0;
n*=2;
for(int i = 1; i <= n; i++) {
int x(read()), y(read()), w(read());
y+=n/2;
adj[x].insert({y,w});
adj[y].insert({x,w});
}
for(int i = 1; i <= n; i++) {
doi(i);
}
while(q.size()) {
int x = q.front(), i = (*adj[x].begin()).first, w= (*adj[x].begin()).second;
del[x] = 1;
q.pop();
adj[i].erase(adj[i].find({x,w}));
doi(i);
}
bt[sum+600000]=1;
for(int i = 1; i <= n; i++) {
if(!del[i]) {
tot = 0;
adj[i].erase(adj[i].begin());
dfs(i, n/2);
bt = shift(tot)|shift(-tot);
}
}
for(int i = -k; i <= k; i++) {
if(bt[600000+i]) {
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
}
Compilation message
tug.cpp: In function 'void dfs(int, int)':
tug.cpp:38:5: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
38 | else
| ^~~~
tug.cpp:40:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
40 | if (!del[nxt]) {
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
10324 KB |
Output is correct |
2 |
Correct |
7 ms |
10324 KB |
Output is correct |
3 |
Correct |
6 ms |
10436 KB |
Output is correct |
4 |
Correct |
6 ms |
10432 KB |
Output is correct |
5 |
Correct |
6 ms |
10324 KB |
Output is correct |
6 |
Correct |
6 ms |
10324 KB |
Output is correct |
7 |
Correct |
6 ms |
10324 KB |
Output is correct |
8 |
Correct |
7 ms |
10324 KB |
Output is correct |
9 |
Correct |
6 ms |
10324 KB |
Output is correct |
10 |
Correct |
6 ms |
10324 KB |
Output is correct |
11 |
Correct |
6 ms |
10324 KB |
Output is correct |
12 |
Correct |
6 ms |
10324 KB |
Output is correct |
13 |
Correct |
6 ms |
10324 KB |
Output is correct |
14 |
Correct |
7 ms |
10324 KB |
Output is correct |
15 |
Correct |
6 ms |
10324 KB |
Output is correct |
16 |
Correct |
7 ms |
10324 KB |
Output is correct |
17 |
Correct |
6 ms |
10436 KB |
Output is correct |
18 |
Correct |
6 ms |
10324 KB |
Output is correct |
19 |
Correct |
7 ms |
10436 KB |
Output is correct |
20 |
Correct |
7 ms |
10440 KB |
Output is correct |
21 |
Correct |
6 ms |
10068 KB |
Output is correct |
22 |
Correct |
6 ms |
10376 KB |
Output is correct |
23 |
Correct |
7 ms |
10324 KB |
Output is correct |
24 |
Correct |
7 ms |
10324 KB |
Output is correct |
25 |
Correct |
8 ms |
10324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
10324 KB |
Output is correct |
2 |
Correct |
7 ms |
10324 KB |
Output is correct |
3 |
Correct |
6 ms |
10436 KB |
Output is correct |
4 |
Correct |
6 ms |
10432 KB |
Output is correct |
5 |
Correct |
6 ms |
10324 KB |
Output is correct |
6 |
Correct |
6 ms |
10324 KB |
Output is correct |
7 |
Correct |
6 ms |
10324 KB |
Output is correct |
8 |
Correct |
7 ms |
10324 KB |
Output is correct |
9 |
Correct |
6 ms |
10324 KB |
Output is correct |
10 |
Correct |
6 ms |
10324 KB |
Output is correct |
11 |
Correct |
6 ms |
10324 KB |
Output is correct |
12 |
Correct |
6 ms |
10324 KB |
Output is correct |
13 |
Correct |
6 ms |
10324 KB |
Output is correct |
14 |
Correct |
7 ms |
10324 KB |
Output is correct |
15 |
Correct |
6 ms |
10324 KB |
Output is correct |
16 |
Correct |
7 ms |
10324 KB |
Output is correct |
17 |
Correct |
6 ms |
10436 KB |
Output is correct |
18 |
Correct |
6 ms |
10324 KB |
Output is correct |
19 |
Correct |
7 ms |
10436 KB |
Output is correct |
20 |
Correct |
7 ms |
10440 KB |
Output is correct |
21 |
Correct |
6 ms |
10068 KB |
Output is correct |
22 |
Correct |
6 ms |
10376 KB |
Output is correct |
23 |
Correct |
7 ms |
10324 KB |
Output is correct |
24 |
Correct |
7 ms |
10324 KB |
Output is correct |
25 |
Correct |
8 ms |
10324 KB |
Output is correct |
26 |
Correct |
114 ms |
10792 KB |
Output is correct |
27 |
Correct |
22 ms |
10812 KB |
Output is correct |
28 |
Correct |
130 ms |
10788 KB |
Output is correct |
29 |
Correct |
23 ms |
10816 KB |
Output is correct |
30 |
Correct |
113 ms |
10792 KB |
Output is correct |
31 |
Correct |
21 ms |
10708 KB |
Output is correct |
32 |
Correct |
130 ms |
10800 KB |
Output is correct |
33 |
Correct |
23 ms |
10764 KB |
Output is correct |
34 |
Correct |
16 ms |
10684 KB |
Output is correct |
35 |
Correct |
24 ms |
10804 KB |
Output is correct |
36 |
Correct |
125 ms |
10788 KB |
Output is correct |
37 |
Correct |
23 ms |
10708 KB |
Output is correct |
38 |
Correct |
112 ms |
10708 KB |
Output is correct |
39 |
Correct |
25 ms |
10712 KB |
Output is correct |
40 |
Correct |
135 ms |
10708 KB |
Output is correct |
41 |
Correct |
25 ms |
10708 KB |
Output is correct |
42 |
Correct |
124 ms |
10796 KB |
Output is correct |
43 |
Correct |
22 ms |
10708 KB |
Output is correct |
44 |
Correct |
108 ms |
10708 KB |
Output is correct |
45 |
Correct |
24 ms |
10808 KB |
Output is correct |
46 |
Correct |
121 ms |
10792 KB |
Output is correct |
47 |
Correct |
6 ms |
10452 KB |
Output is correct |
48 |
Correct |
62 ms |
10792 KB |
Output is correct |
49 |
Correct |
60 ms |
10708 KB |
Output is correct |
50 |
Correct |
116 ms |
10792 KB |
Output is correct |
51 |
Correct |
113 ms |
10788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
383 ms |
12308 KB |
Output is correct |
2 |
Correct |
11 ms |
11988 KB |
Output is correct |
3 |
Correct |
404 ms |
12308 KB |
Output is correct |
4 |
Correct |
11 ms |
11920 KB |
Output is correct |
5 |
Correct |
399 ms |
12316 KB |
Output is correct |
6 |
Correct |
12 ms |
11988 KB |
Output is correct |
7 |
Correct |
405 ms |
12300 KB |
Output is correct |
8 |
Correct |
11 ms |
11988 KB |
Output is correct |
9 |
Correct |
323 ms |
12312 KB |
Output is correct |
10 |
Correct |
11 ms |
11988 KB |
Output is correct |
11 |
Correct |
378 ms |
12312 KB |
Output is correct |
12 |
Correct |
13 ms |
11944 KB |
Output is correct |
13 |
Correct |
381 ms |
12436 KB |
Output is correct |
14 |
Correct |
378 ms |
12492 KB |
Output is correct |
15 |
Correct |
11 ms |
11988 KB |
Output is correct |
16 |
Correct |
398 ms |
12312 KB |
Output is correct |
17 |
Correct |
12 ms |
12020 KB |
Output is correct |
18 |
Correct |
363 ms |
12308 KB |
Output is correct |
19 |
Correct |
11 ms |
11988 KB |
Output is correct |
20 |
Correct |
410 ms |
12244 KB |
Output is correct |
21 |
Correct |
12 ms |
11988 KB |
Output is correct |
22 |
Correct |
203 ms |
12352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
10324 KB |
Output is correct |
2 |
Correct |
7 ms |
10324 KB |
Output is correct |
3 |
Correct |
6 ms |
10436 KB |
Output is correct |
4 |
Correct |
6 ms |
10432 KB |
Output is correct |
5 |
Correct |
6 ms |
10324 KB |
Output is correct |
6 |
Correct |
6 ms |
10324 KB |
Output is correct |
7 |
Correct |
6 ms |
10324 KB |
Output is correct |
8 |
Correct |
7 ms |
10324 KB |
Output is correct |
9 |
Correct |
6 ms |
10324 KB |
Output is correct |
10 |
Correct |
6 ms |
10324 KB |
Output is correct |
11 |
Correct |
6 ms |
10324 KB |
Output is correct |
12 |
Correct |
6 ms |
10324 KB |
Output is correct |
13 |
Correct |
6 ms |
10324 KB |
Output is correct |
14 |
Correct |
7 ms |
10324 KB |
Output is correct |
15 |
Correct |
6 ms |
10324 KB |
Output is correct |
16 |
Correct |
7 ms |
10324 KB |
Output is correct |
17 |
Correct |
6 ms |
10436 KB |
Output is correct |
18 |
Correct |
6 ms |
10324 KB |
Output is correct |
19 |
Correct |
7 ms |
10436 KB |
Output is correct |
20 |
Correct |
7 ms |
10440 KB |
Output is correct |
21 |
Correct |
6 ms |
10068 KB |
Output is correct |
22 |
Correct |
6 ms |
10376 KB |
Output is correct |
23 |
Correct |
7 ms |
10324 KB |
Output is correct |
24 |
Correct |
7 ms |
10324 KB |
Output is correct |
25 |
Correct |
8 ms |
10324 KB |
Output is correct |
26 |
Correct |
114 ms |
10792 KB |
Output is correct |
27 |
Correct |
22 ms |
10812 KB |
Output is correct |
28 |
Correct |
130 ms |
10788 KB |
Output is correct |
29 |
Correct |
23 ms |
10816 KB |
Output is correct |
30 |
Correct |
113 ms |
10792 KB |
Output is correct |
31 |
Correct |
21 ms |
10708 KB |
Output is correct |
32 |
Correct |
130 ms |
10800 KB |
Output is correct |
33 |
Correct |
23 ms |
10764 KB |
Output is correct |
34 |
Correct |
16 ms |
10684 KB |
Output is correct |
35 |
Correct |
24 ms |
10804 KB |
Output is correct |
36 |
Correct |
125 ms |
10788 KB |
Output is correct |
37 |
Correct |
23 ms |
10708 KB |
Output is correct |
38 |
Correct |
112 ms |
10708 KB |
Output is correct |
39 |
Correct |
25 ms |
10712 KB |
Output is correct |
40 |
Correct |
135 ms |
10708 KB |
Output is correct |
41 |
Correct |
25 ms |
10708 KB |
Output is correct |
42 |
Correct |
124 ms |
10796 KB |
Output is correct |
43 |
Correct |
22 ms |
10708 KB |
Output is correct |
44 |
Correct |
108 ms |
10708 KB |
Output is correct |
45 |
Correct |
24 ms |
10808 KB |
Output is correct |
46 |
Correct |
121 ms |
10792 KB |
Output is correct |
47 |
Correct |
6 ms |
10452 KB |
Output is correct |
48 |
Correct |
62 ms |
10792 KB |
Output is correct |
49 |
Correct |
60 ms |
10708 KB |
Output is correct |
50 |
Correct |
116 ms |
10792 KB |
Output is correct |
51 |
Correct |
113 ms |
10788 KB |
Output is correct |
52 |
Correct |
383 ms |
12308 KB |
Output is correct |
53 |
Correct |
11 ms |
11988 KB |
Output is correct |
54 |
Correct |
404 ms |
12308 KB |
Output is correct |
55 |
Correct |
11 ms |
11920 KB |
Output is correct |
56 |
Correct |
399 ms |
12316 KB |
Output is correct |
57 |
Correct |
12 ms |
11988 KB |
Output is correct |
58 |
Correct |
405 ms |
12300 KB |
Output is correct |
59 |
Correct |
11 ms |
11988 KB |
Output is correct |
60 |
Correct |
323 ms |
12312 KB |
Output is correct |
61 |
Correct |
11 ms |
11988 KB |
Output is correct |
62 |
Correct |
378 ms |
12312 KB |
Output is correct |
63 |
Correct |
13 ms |
11944 KB |
Output is correct |
64 |
Correct |
381 ms |
12436 KB |
Output is correct |
65 |
Correct |
378 ms |
12492 KB |
Output is correct |
66 |
Correct |
11 ms |
11988 KB |
Output is correct |
67 |
Correct |
398 ms |
12312 KB |
Output is correct |
68 |
Correct |
12 ms |
12020 KB |
Output is correct |
69 |
Correct |
363 ms |
12308 KB |
Output is correct |
70 |
Correct |
11 ms |
11988 KB |
Output is correct |
71 |
Correct |
410 ms |
12244 KB |
Output is correct |
72 |
Correct |
12 ms |
11988 KB |
Output is correct |
73 |
Correct |
203 ms |
12352 KB |
Output is correct |
74 |
Correct |
1810 ms |
16348 KB |
Output is correct |
75 |
Correct |
108 ms |
16112 KB |
Output is correct |
76 |
Correct |
1706 ms |
16224 KB |
Output is correct |
77 |
Correct |
102 ms |
16084 KB |
Output is correct |
78 |
Correct |
1710 ms |
16220 KB |
Output is correct |
79 |
Correct |
1726 ms |
16220 KB |
Output is correct |
80 |
Correct |
96 ms |
16032 KB |
Output is correct |
81 |
Correct |
100 ms |
16080 KB |
Output is correct |
82 |
Correct |
1810 ms |
16352 KB |
Output is correct |
83 |
Correct |
1603 ms |
16100 KB |
Output is correct |
84 |
Correct |
116 ms |
16108 KB |
Output is correct |
85 |
Correct |
1608 ms |
16340 KB |
Output is correct |
86 |
Correct |
99 ms |
16104 KB |
Output is correct |
87 |
Correct |
1805 ms |
16216 KB |
Output is correct |
88 |
Correct |
108 ms |
16112 KB |
Output is correct |
89 |
Correct |
1722 ms |
16348 KB |
Output is correct |
90 |
Correct |
112 ms |
16096 KB |
Output is correct |
91 |
Correct |
1697 ms |
16224 KB |
Output is correct |
92 |
Correct |
109 ms |
16100 KB |
Output is correct |
93 |
Correct |
1803 ms |
16172 KB |
Output is correct |
94 |
Correct |
28 ms |
15700 KB |
Output is correct |
95 |
Correct |
931 ms |
16208 KB |
Output is correct |
96 |
Correct |
924 ms |
16204 KB |
Output is correct |
97 |
Correct |
1764 ms |
16584 KB |
Output is correct |
98 |
Correct |
1873 ms |
16108 KB |
Output is correct |