Submission #418073

#TimeUsernameProblemLanguageResultExecution timeMemory
418073JerryLiu06Tug of War (BOI15_tug)C++17
71 / 100
188 ms4556 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using db = double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<db, db>; using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>; using vd = vector<db>; using vs = vector<str>; using vpi = vector<pi>; using vpl = vector<pl>; using vpd = vector<pd>; #define mp make_pair #define f first #define s second #define sz(x) (int)(x).size() #define bg(x) begin(x) #define all(x) bg(x), end(x) #define sor(x) sort(all(x)) #define ft front() #define bk back() #define pb push_back #define pf push_front #define lb lower_bound #define ub upper_bound #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define EACH(a,x) for (auto& a: x) const int MOD = 1e9 + 7; const int MX = 3e4 + 10; const ll INF = 1e18; int N, K; multiset<pi> adj[MX]; int inDeg[MX], tot; bool vis[MX]; vi todo; void DFS(int X) { vis[X] = true; pi E = *adj[X].bg(); tot += E.s; if (!vis[E.f]) { adj[X].clear(); adj[E.f].erase(adj[E.f].find({X, -E.s})); DFS(E.f); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N >> K; F0R(i, 2 * N) { int A, B, S; cin >> A >> B >> S; adj[A].insert({N + B, S}), adj[N + B].insert({A, -S}); } queue<int> Q; FOR(i, 1, 2 * N + 1) { if (sz(adj[i]) == 0) { cout << "NO"; return 0; } if (sz(adj[i]) == 1) Q.push(i); } while (!Q.empty()) { int cur = Q.front(); Q.pop(); if (sz(adj[cur]) == 0) { cout << "NO"; return 0; } pi E = *adj[cur].bg(); tot += E.s; adj[cur].clear(); adj[E.f].erase(adj[E.f].find({cur, -E.s})); if (sz(adj[E.f]) == 1) Q.push(E.f); } if (tot) todo.pb(abs(tot)); FOR(i, 1, 2 * N + 1) if (!vis[i] && sz(adj[i])) { tot = 0; adj[i].erase(adj[i].bg()); DFS(i); if (tot) todo.pb(abs(tot)); } bitset<40 * MX> DP; DP[20 * MX] = 1;EACH(C, todo) DP = (DP << C) | (DP >> C); FOR(i, 20 * MX - K, 20 * MX + K + 1) if (DP[i]) { cout << "YES"; return 0; } cout << "NO"; }

Compilation message (stderr)

tug.cpp: In function 'int main()':
tug.cpp:39:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   39 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
      |                    ^~~
tug.cpp:82:5: note: in expansion of macro 'FOR'
   82 |     FOR(i, 20 * MX - K, 20 * MX + K + 1) if (DP[i]) { cout << "YES"; return 0; } cout << "NO";
      |     ^~~
tug.cpp:82:82: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   82 |     FOR(i, 20 * MX - K, 20 * MX + K + 1) if (DP[i]) { cout << "YES"; return 0; } cout << "NO";
      |                                                                                  ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...