# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
94120 | Kastanda | Tug of War (BOI15_tug) | C++11 | 104 ms | 6520 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 30004, MXN = N * 20;
int n, k, L[N], R[N], A[N], C[MXN];
bool M[N * 2];
set < int > Adj[N * 2];
bitset < MXN > B;
int Brute()
{
int nn = n + n;
vector < int > T[30];
for (int i = 0; i < (1 << nn); i++)
{
for (int j = 1; j <= nn; j++)
T[j].clear();
for (int j = 0; j < nn; j++)
{
int id = j + 1;
if (i >> j & 1)
{
T[L[id]].push_back(id);
}
else
{
T[R[id]].push_back(id);
}
}
int sum = 0, fail = 0;
for (int j = 1; j <= n + n; j++)
{
if (T[j].size() != 1)
{fail = 1; break;}
if (j <= n)
sum += A[T[j][0]];
else
sum -= A[T[j][0]];
}
if (fail == 0 && abs(sum) <= k)
return 1;
}
return 0;
}
int main()
{
scanf("%d%d", &n, &k);
for (int i = 1; i <= n + n; i++)
scanf("%d%d%d", &L[i], &R[i], &A[i]), R[i] += n;
if (Brute())
printf("YES");
else
printf("NO");
return (0);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |