Submission #252794

#TimeUsernameProblemLanguageResultExecution timeMemory
252794BlagojceTug of War (BOI15_tug)C++11
0 / 100
24 ms13696 KiB
#include <bits/stdc++.h> #define fr(i, n, m) for(int i = (n); i < (m); i ++) #define pb push_back #define st first #define nd second #define pq priority_queue #define all(x) begin(x), end(x) #include <time.h> #include <cmath> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; const int i_inf = 1e9; const ll inf = 1e18; const ll mod = 1000000007; const ld eps = 1e-13; const ld pi = 3.14159265359; mt19937 _rand(time(NULL)); clock_t timer = clock(); const int mxn = 5e5; int l[mxn], r[mxn], s[mxn]; int n, k; vector<int> g[mxn]; int used[mxn]; int vis[mxn]; int tempa, tempb; int trans(int u, int ed){ if(u == l[ed]){ tempb += s[ed]; return r[ed]; } else{ tempa += s[ed]; return l[ed]; } } bool OK; void dfs(int u, int flag){ for(auto e : g[u]){ if(used[e] == flag) continue; used[e] = flag; int nx = trans(u, e); if(vis[nx] == flag){ OK = false; } vis[nx] = flag; dfs(nx, flag); } } void solve(){ cin >> n>> k; n *= 2; fr(i, 0, n){ cin >> l[i] >> r[i] >> s[i]; r[i] += n/2; --l[i], --r[i]; } int suma = 0; int sumb = 0; int deg[n]; memset(deg, 0, sizeof(deg)); fr(i, 0, n){ deg[l[i]]++; deg[r[i]]++; } fr(i, 0, n){ if(deg[l[i]] == 1 && deg[r[i]] == 1){ cout<<"NO"<<endl; return; } if(deg[l[i]] == 1){ suma += s[i]; } else if(deg[r[i]] == 1){ sumb += s[i]; } else{ g[l[i]].pb(i); g[r[i]].pb(i); } } vector<pii> diff; fr(i, 0, n){ if(used[i] == 2) continue; tempa = 0, tempb = 0; OK = true; dfs(l[i], 1); int F = tempa-tempb; if(!OK){ F = -i_inf; } tempa = 0, tempb = 0; OK = true; dfs(r[i], 2); int S = tempa-tempb; if(!OK){ S = -i_inf; } if(F == -i_inf&&S==-i_inf){ cout<<"NO"<<endl; return; } diff.pb({F, S}); } int base = n*20; cout<<"YES"<<endl; //for(auto u : diff) cout<<u.st<<' '<<u.nd<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }

Compilation message (stderr)

tug.cpp: In function 'void solve()':
tug.cpp:118:6: warning: unused variable 'base' [-Wunused-variable]
  int base = n*20; 
      ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...