# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
480985 |
2021-10-19T04:56:56 Z |
pure_mem |
Tug of War (BOI15_tug) |
C++17 |
|
641 ms |
8448 KB |
#include <bits/stdc++.h>
#define ll long long
#define X first
#define Y second
#define MP make_pair
using namespace std;
const int N = 6e4 + 1, M = 10 * N;
const int mod = 1e9 + 7;
int n, k, deg[N], vis[N], w[N];
vector< pair<int, int> > g[N];
bitset<M> dp;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> k;
int sum = 0;
for(int i = 1, x, y;i <= n + n;i++) {
cin >> x >> y >> w[i], y += n;
g[x].push_back(MP(y, i)), deg[x]++;
g[y].push_back(MP(x, i)), deg[y]++;
}
{
set< pair<int, int> > st;
for(int i = 1;i <= n + n;i++)
st.insert(MP(deg[i], i));
while(!st.empty()) {
int pos = st.begin()->Y;
st.erase(st.begin());
if(deg[pos] == 0) return cout << "NO", 0;
else if(deg[pos] != 1) break;
for(auto [to, id]: g[pos]) {
if(vis[id]) continue;
vis[id] = 1;
st.erase(MP(deg[to], to));
if(pos > n) sum -= w[id];
else sum += w[id];
deg[to]--, deg[pos]--;
st.insert(MP(deg[to], to));
break;
}
}
}
dp[0] = 1;
for(int i = 1;i <= n + n;i++) {
int bl = 0;
function<void(int)> dfs;
dfs = [&](int v){
int cnt = 0;
for(auto [to, id]: g[v]) {
if(vis[id]) continue;
vis[id] = 1;
if(v <= n) bl += w[id];
else bl -= w[id];
dfs(to);
cnt++;
}
assert(cnt <= 1);
};
dfs(i);
if(bl == 0) continue;
bl = abs(bl), sum += bl, dp |= dp << bl;
}
string ans = "NO";
for(int i = 0;i < M;i++) {
if(dp[i] && abs(sum - 2 * i) <= k) {
ans = "YES";
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1868 KB |
Output is correct |
2 |
Correct |
2 ms |
1868 KB |
Output is correct |
3 |
Correct |
2 ms |
1872 KB |
Output is correct |
4 |
Correct |
2 ms |
1956 KB |
Output is correct |
5 |
Correct |
2 ms |
1868 KB |
Output is correct |
6 |
Correct |
2 ms |
1868 KB |
Output is correct |
7 |
Correct |
2 ms |
1868 KB |
Output is correct |
8 |
Correct |
2 ms |
1868 KB |
Output is correct |
9 |
Correct |
2 ms |
1868 KB |
Output is correct |
10 |
Correct |
3 ms |
1868 KB |
Output is correct |
11 |
Correct |
3 ms |
1868 KB |
Output is correct |
12 |
Correct |
3 ms |
1868 KB |
Output is correct |
13 |
Correct |
2 ms |
1868 KB |
Output is correct |
14 |
Correct |
3 ms |
1868 KB |
Output is correct |
15 |
Correct |
2 ms |
1872 KB |
Output is correct |
16 |
Correct |
2 ms |
1868 KB |
Output is correct |
17 |
Correct |
2 ms |
1868 KB |
Output is correct |
18 |
Correct |
2 ms |
1868 KB |
Output is correct |
19 |
Correct |
2 ms |
1868 KB |
Output is correct |
20 |
Correct |
2 ms |
1884 KB |
Output is correct |
21 |
Correct |
2 ms |
1872 KB |
Output is correct |
22 |
Correct |
2 ms |
1868 KB |
Output is correct |
23 |
Correct |
2 ms |
1868 KB |
Output is correct |
24 |
Correct |
2 ms |
1868 KB |
Output is correct |
25 |
Correct |
2 ms |
1948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1868 KB |
Output is correct |
2 |
Correct |
2 ms |
1868 KB |
Output is correct |
3 |
Correct |
2 ms |
1872 KB |
Output is correct |
4 |
Correct |
2 ms |
1956 KB |
Output is correct |
5 |
Correct |
2 ms |
1868 KB |
Output is correct |
6 |
Correct |
2 ms |
1868 KB |
Output is correct |
7 |
Correct |
2 ms |
1868 KB |
Output is correct |
8 |
Correct |
2 ms |
1868 KB |
Output is correct |
9 |
Correct |
2 ms |
1868 KB |
Output is correct |
10 |
Correct |
3 ms |
1868 KB |
Output is correct |
11 |
Correct |
3 ms |
1868 KB |
Output is correct |
12 |
Correct |
3 ms |
1868 KB |
Output is correct |
13 |
Correct |
2 ms |
1868 KB |
Output is correct |
14 |
Correct |
3 ms |
1868 KB |
Output is correct |
15 |
Correct |
2 ms |
1872 KB |
Output is correct |
16 |
Correct |
2 ms |
1868 KB |
Output is correct |
17 |
Correct |
2 ms |
1868 KB |
Output is correct |
18 |
Correct |
2 ms |
1868 KB |
Output is correct |
19 |
Correct |
2 ms |
1868 KB |
Output is correct |
20 |
Correct |
2 ms |
1884 KB |
Output is correct |
21 |
Correct |
2 ms |
1872 KB |
Output is correct |
22 |
Correct |
2 ms |
1868 KB |
Output is correct |
23 |
Correct |
2 ms |
1868 KB |
Output is correct |
24 |
Correct |
2 ms |
1868 KB |
Output is correct |
25 |
Correct |
2 ms |
1948 KB |
Output is correct |
26 |
Correct |
41 ms |
2252 KB |
Output is correct |
27 |
Correct |
10 ms |
2252 KB |
Output is correct |
28 |
Correct |
41 ms |
2252 KB |
Output is correct |
29 |
Correct |
9 ms |
2252 KB |
Output is correct |
30 |
Correct |
39 ms |
2252 KB |
Output is correct |
31 |
Correct |
10 ms |
2356 KB |
Output is correct |
32 |
Correct |
45 ms |
2372 KB |
Output is correct |
33 |
Correct |
9 ms |
2364 KB |
Output is correct |
34 |
Correct |
6 ms |
2252 KB |
Output is correct |
35 |
Correct |
9 ms |
2252 KB |
Output is correct |
36 |
Correct |
39 ms |
2252 KB |
Output is correct |
37 |
Correct |
9 ms |
2272 KB |
Output is correct |
38 |
Correct |
40 ms |
2252 KB |
Output is correct |
39 |
Correct |
10 ms |
2268 KB |
Output is correct |
40 |
Correct |
40 ms |
2348 KB |
Output is correct |
41 |
Correct |
9 ms |
2252 KB |
Output is correct |
42 |
Correct |
44 ms |
2252 KB |
Output is correct |
43 |
Correct |
10 ms |
2364 KB |
Output is correct |
44 |
Correct |
40 ms |
2252 KB |
Output is correct |
45 |
Correct |
10 ms |
2252 KB |
Output is correct |
46 |
Correct |
57 ms |
2336 KB |
Output is correct |
47 |
Correct |
4 ms |
2252 KB |
Output is correct |
48 |
Correct |
23 ms |
2336 KB |
Output is correct |
49 |
Correct |
23 ms |
2380 KB |
Output is correct |
50 |
Correct |
45 ms |
2336 KB |
Output is correct |
51 |
Correct |
44 ms |
2276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
3916 KB |
Output is correct |
2 |
Correct |
11 ms |
3932 KB |
Output is correct |
3 |
Correct |
16 ms |
3808 KB |
Output is correct |
4 |
Correct |
11 ms |
3916 KB |
Output is correct |
5 |
Correct |
12 ms |
3828 KB |
Output is correct |
6 |
Correct |
18 ms |
3912 KB |
Output is correct |
7 |
Correct |
13 ms |
3808 KB |
Output is correct |
8 |
Correct |
12 ms |
3908 KB |
Output is correct |
9 |
Correct |
13 ms |
3916 KB |
Output is correct |
10 |
Correct |
12 ms |
3916 KB |
Output is correct |
11 |
Correct |
13 ms |
3808 KB |
Output is correct |
12 |
Correct |
13 ms |
3880 KB |
Output is correct |
13 |
Correct |
12 ms |
3808 KB |
Output is correct |
14 |
Correct |
13 ms |
3800 KB |
Output is correct |
15 |
Correct |
13 ms |
3916 KB |
Output is correct |
16 |
Correct |
14 ms |
3916 KB |
Output is correct |
17 |
Correct |
11 ms |
3916 KB |
Output is correct |
18 |
Correct |
14 ms |
3896 KB |
Output is correct |
19 |
Correct |
11 ms |
3916 KB |
Output is correct |
20 |
Correct |
17 ms |
3904 KB |
Output is correct |
21 |
Correct |
11 ms |
3788 KB |
Output is correct |
22 |
Correct |
17 ms |
3932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1868 KB |
Output is correct |
2 |
Correct |
2 ms |
1868 KB |
Output is correct |
3 |
Correct |
2 ms |
1872 KB |
Output is correct |
4 |
Correct |
2 ms |
1956 KB |
Output is correct |
5 |
Correct |
2 ms |
1868 KB |
Output is correct |
6 |
Correct |
2 ms |
1868 KB |
Output is correct |
7 |
Correct |
2 ms |
1868 KB |
Output is correct |
8 |
Correct |
2 ms |
1868 KB |
Output is correct |
9 |
Correct |
2 ms |
1868 KB |
Output is correct |
10 |
Correct |
3 ms |
1868 KB |
Output is correct |
11 |
Correct |
3 ms |
1868 KB |
Output is correct |
12 |
Correct |
3 ms |
1868 KB |
Output is correct |
13 |
Correct |
2 ms |
1868 KB |
Output is correct |
14 |
Correct |
3 ms |
1868 KB |
Output is correct |
15 |
Correct |
2 ms |
1872 KB |
Output is correct |
16 |
Correct |
2 ms |
1868 KB |
Output is correct |
17 |
Correct |
2 ms |
1868 KB |
Output is correct |
18 |
Correct |
2 ms |
1868 KB |
Output is correct |
19 |
Correct |
2 ms |
1868 KB |
Output is correct |
20 |
Correct |
2 ms |
1884 KB |
Output is correct |
21 |
Correct |
2 ms |
1872 KB |
Output is correct |
22 |
Correct |
2 ms |
1868 KB |
Output is correct |
23 |
Correct |
2 ms |
1868 KB |
Output is correct |
24 |
Correct |
2 ms |
1868 KB |
Output is correct |
25 |
Correct |
2 ms |
1948 KB |
Output is correct |
26 |
Correct |
41 ms |
2252 KB |
Output is correct |
27 |
Correct |
10 ms |
2252 KB |
Output is correct |
28 |
Correct |
41 ms |
2252 KB |
Output is correct |
29 |
Correct |
9 ms |
2252 KB |
Output is correct |
30 |
Correct |
39 ms |
2252 KB |
Output is correct |
31 |
Correct |
10 ms |
2356 KB |
Output is correct |
32 |
Correct |
45 ms |
2372 KB |
Output is correct |
33 |
Correct |
9 ms |
2364 KB |
Output is correct |
34 |
Correct |
6 ms |
2252 KB |
Output is correct |
35 |
Correct |
9 ms |
2252 KB |
Output is correct |
36 |
Correct |
39 ms |
2252 KB |
Output is correct |
37 |
Correct |
9 ms |
2272 KB |
Output is correct |
38 |
Correct |
40 ms |
2252 KB |
Output is correct |
39 |
Correct |
10 ms |
2268 KB |
Output is correct |
40 |
Correct |
40 ms |
2348 KB |
Output is correct |
41 |
Correct |
9 ms |
2252 KB |
Output is correct |
42 |
Correct |
44 ms |
2252 KB |
Output is correct |
43 |
Correct |
10 ms |
2364 KB |
Output is correct |
44 |
Correct |
40 ms |
2252 KB |
Output is correct |
45 |
Correct |
10 ms |
2252 KB |
Output is correct |
46 |
Correct |
57 ms |
2336 KB |
Output is correct |
47 |
Correct |
4 ms |
2252 KB |
Output is correct |
48 |
Correct |
23 ms |
2336 KB |
Output is correct |
49 |
Correct |
23 ms |
2380 KB |
Output is correct |
50 |
Correct |
45 ms |
2336 KB |
Output is correct |
51 |
Correct |
44 ms |
2276 KB |
Output is correct |
52 |
Correct |
14 ms |
3916 KB |
Output is correct |
53 |
Correct |
11 ms |
3932 KB |
Output is correct |
54 |
Correct |
16 ms |
3808 KB |
Output is correct |
55 |
Correct |
11 ms |
3916 KB |
Output is correct |
56 |
Correct |
12 ms |
3828 KB |
Output is correct |
57 |
Correct |
18 ms |
3912 KB |
Output is correct |
58 |
Correct |
13 ms |
3808 KB |
Output is correct |
59 |
Correct |
12 ms |
3908 KB |
Output is correct |
60 |
Correct |
13 ms |
3916 KB |
Output is correct |
61 |
Correct |
12 ms |
3916 KB |
Output is correct |
62 |
Correct |
13 ms |
3808 KB |
Output is correct |
63 |
Correct |
13 ms |
3880 KB |
Output is correct |
64 |
Correct |
12 ms |
3808 KB |
Output is correct |
65 |
Correct |
13 ms |
3800 KB |
Output is correct |
66 |
Correct |
13 ms |
3916 KB |
Output is correct |
67 |
Correct |
14 ms |
3916 KB |
Output is correct |
68 |
Correct |
11 ms |
3916 KB |
Output is correct |
69 |
Correct |
14 ms |
3896 KB |
Output is correct |
70 |
Correct |
11 ms |
3916 KB |
Output is correct |
71 |
Correct |
17 ms |
3904 KB |
Output is correct |
72 |
Correct |
11 ms |
3788 KB |
Output is correct |
73 |
Correct |
17 ms |
3932 KB |
Output is correct |
74 |
Correct |
587 ms |
8136 KB |
Output is correct |
75 |
Correct |
74 ms |
8024 KB |
Output is correct |
76 |
Correct |
615 ms |
8252 KB |
Output is correct |
77 |
Correct |
70 ms |
8136 KB |
Output is correct |
78 |
Correct |
602 ms |
8260 KB |
Output is correct |
79 |
Correct |
600 ms |
8140 KB |
Output is correct |
80 |
Correct |
63 ms |
8132 KB |
Output is correct |
81 |
Correct |
70 ms |
8016 KB |
Output is correct |
82 |
Correct |
633 ms |
8240 KB |
Output is correct |
83 |
Correct |
641 ms |
8136 KB |
Output is correct |
84 |
Correct |
75 ms |
8132 KB |
Output is correct |
85 |
Correct |
594 ms |
8136 KB |
Output is correct |
86 |
Correct |
66 ms |
8036 KB |
Output is correct |
87 |
Correct |
607 ms |
8068 KB |
Output is correct |
88 |
Correct |
70 ms |
8132 KB |
Output is correct |
89 |
Correct |
614 ms |
8136 KB |
Output is correct |
90 |
Correct |
64 ms |
8132 KB |
Output is correct |
91 |
Correct |
591 ms |
8132 KB |
Output is correct |
92 |
Correct |
70 ms |
8092 KB |
Output is correct |
93 |
Correct |
597 ms |
8132 KB |
Output is correct |
94 |
Correct |
39 ms |
8004 KB |
Output is correct |
95 |
Correct |
336 ms |
8448 KB |
Output is correct |
96 |
Correct |
344 ms |
8444 KB |
Output is correct |
97 |
Correct |
628 ms |
8132 KB |
Output is correct |
98 |
Correct |
610 ms |
8132 KB |
Output is correct |