# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
677213 |
2023-01-02T14:59:28 Z |
ajab_01 |
Tug of War (BOI15_tug) |
C++17 |
|
13 ms |
5204 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> g[N];
int l[N] , r[N] , p[N] , cnt[2] , n , k;
bool mark[N] , ch , flg = 1;
void dfs(int ver , int sit){
mark[ver] = 1;
cnt[sit]++;
for(int i : g[ver]){
if(mark[i]) continue;
dfs(i , sit ^ 1);
}
}
bool check(int mask){
bool vis[11];
memset(vis , 0 , sizeof(vis));
int sum1 = 0 , sum2 = 0;
for(int i = 0 ; i < 2 * n ; i++){
if(mask & (1 << i)){
if(vis[r[i]])
return 0;
vis[r[i]] = 1;
sum1 += p[i];
}
else{
if(vis[l[i]])
return 0;
vis[l[i]] = 1;
sum2 += p[i];
}
}
return abs(sum1 - sum2) <= k;
}
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> k;
if(n <= 10){
for(int i = 0 ; i < 2 * n ; i++){
cin >> l[i] >> r[i] >> p[i];
r[i] += n;
}
for(int mask = 0 ; mask < (1 << 2 * n) ; mask++)
if(check(mask))
ch = 1;
if(ch)
cout << "YES" << '\n';
else
cout << "NO" << '\n';
return 0;
}
for(int i = 1 ; i <= 2 * n ; i++){
cin >> l[i] >> r[i] >> p[i];
g[i].push_back(l[i] + 2 * n);
g[l[i] + 2 * n].push_back(i);
g[i].push_back(r[i] + 3 * n);
g[r[i] + 3 * n].push_back(i);
}
for(int i = 1 ; i <= 4 * n ; i++){
if(!mark[i]){
cnt[0] = cnt[1] = 0;
dfs(i , (i > 2 * n ? 1 : 0));
if(cnt[0] != cnt[1]) flg = 0;
}
}
if(flg)
cout << "YES" << '\n';
else
cout << "NO" << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
5204 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
5204 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4180 KB |
Output is correct |
2 |
Correct |
10 ms |
4140 KB |
Output is correct |
3 |
Correct |
9 ms |
4140 KB |
Output is correct |
4 |
Correct |
10 ms |
4192 KB |
Output is correct |
5 |
Correct |
9 ms |
4188 KB |
Output is correct |
6 |
Correct |
11 ms |
4192 KB |
Output is correct |
7 |
Correct |
9 ms |
4180 KB |
Output is correct |
8 |
Correct |
10 ms |
4180 KB |
Output is correct |
9 |
Correct |
13 ms |
4180 KB |
Output is correct |
10 |
Correct |
12 ms |
4144 KB |
Output is correct |
11 |
Correct |
11 ms |
4164 KB |
Output is correct |
12 |
Correct |
11 ms |
4160 KB |
Output is correct |
13 |
Correct |
10 ms |
4128 KB |
Output is correct |
14 |
Correct |
10 ms |
4112 KB |
Output is correct |
15 |
Correct |
10 ms |
4180 KB |
Output is correct |
16 |
Correct |
9 ms |
4180 KB |
Output is correct |
17 |
Correct |
10 ms |
4196 KB |
Output is correct |
18 |
Correct |
9 ms |
4188 KB |
Output is correct |
19 |
Correct |
11 ms |
4180 KB |
Output is correct |
20 |
Correct |
9 ms |
4180 KB |
Output is correct |
21 |
Correct |
10 ms |
4436 KB |
Output is correct |
22 |
Correct |
10 ms |
4180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
5204 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |