Submission #252806

#TimeUsernameProblemLanguageResultExecution timeMemory
252806BlagojceTug of War (BOI15_tug)C++11
0 / 100
10 ms12160 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; vis[l[i]] = 1; used[i] = 1; OK = true; dfs(l[i], 1); bool ok1 = OK; vis[r[i]] = 2; used[i] = 2; OK = true; dfs(r[i], 2); bool ok2 = OK; if(!ok1 && !ok2){ cout<<"NO"<<endl; return; } /* 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<<i<<"NO"<<endl; return; } diff.pb({F, S});*/ } cout<<"YES"<<endl; } int main(){ freopen("tug3b.in", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }

Compilation message (stderr)

tug.cpp: In function 'int main()':
tug.cpp:146:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("tug3b.in", "r", stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...