#include <iostream>
#include <vector>
using namespace std;
bool bt(int i,vector<pair<int,int>> pos,int l,int r,int k,vector<int>& posl,vector<int>& posr,vector<int>& s){
if(i==pos.size()&&abs(l-r)<=k)return true;
if(posl[pos[i].first]){
posl[pos[i].first]=0;
l+=s[i];
if(bt(i+1,pos,l,r,k,posl,posr,s))return true;
posl[pos[i].first]=1;
l-=s[i];
}
if(posr[pos[i].second]){
posr[pos[i].second]=0;
r+=s[i];
if(bt(i+1,pos,l,r,k,posl,posr,s))return true;
posr[pos[i].second]=1;
r-=s[i];
}
return false;
}
int main(){
int n,k;
cin>>n>>k;
vector<pair<int,int>> pos(2*n);
vector<int> posl(n,1),posr(n,1),s(2*n);
for(int i=0;i<2*n;i++)cin>>pos[i].first>>pos[i].second>>s[i];
for(int i=0;i<2*n;i++){
pos[i].first--;pos[i].second--;
}
if(bt(0,pos,0,0,k,posl,posr,s))cout<<"YES\n";
else cout<<"NO\n";
}
Compilation message
tug.cpp: In function 'bool bt(int, std::vector<std::pair<int, int> >, int, int, int, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
tug.cpp:5:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | if(i==pos.size()&&abs(l-r)<=k)return true;
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
107 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |