# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
559318 |
2022-05-09T15:21:25 Z |
Olympia |
Tug of War (BOI15_tug) |
C++17 |
|
34 ms |
7420 KB |
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int,int> > > adj;
vector<bool> hasVisited;
int ans = 0;
void dfs (int curNode, int prevNode) {
if (hasVisited[curNode]) {
return;
}
hasVisited[curNode] = true;
for (pair<int,int> p: adj[curNode]) {
if (p.first != prevNode) {
ans += p.second;
dfs (p.first, curNode);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
adj.resize(2 * n);
hasVisited.assign(2 * n, false);
map<pair<int,int>,vector<int> > myMap;
for (int i = 0; i < 2 * n; i++) {
int u, v, w;
cin >> u >> v >> w;
u--, v--;
v += n;
myMap[make_pair(u, v)].push_back(w);
adj[u].push_back(make_pair(v, w));
adj[v].push_back(make_pair(u, -w));
}
vector<int> tot;
for (int i = 0; i < n; i++) {
if (!hasVisited[i]) {
ans = 0;
dfs (i, adj[i].back().first);
//cout << ans << '\n';
tot.push_back(ans);
}
}
for (auto& p: myMap) {
if (p.second.size() <= 1) {
continue;
}
int a = 0;
for (int j = 0; j < p.second.size(); j++) {
if (j % 2) a += p.second[j];
else a -= p.second[j];
}
tot.push_back(a);
}
bitset<30000> bs;
bs.set(0);
for (int j: tot) {
bs = bs | (bs << j);
}
for (int i = 0; i <= k; i++) {
if (bs[i]) {
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
}
Compilation message
tug.cpp: In function 'int main()':
tug.cpp:50:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int j = 0; j < p.second.size(); j++) {
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
2900 KB |
Output is correct |
2 |
Runtime error |
18 ms |
7420 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |