제출 #130049

#제출 시각아이디문제언어결과실행 시간메모리
130049nikolapesic2802Tug of War (BOI15_tug)C++14
0 / 100
3030 ms5752 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ll long long #define pb push_back #define sz(x) (int)(x).size() #define mp make_pair #define f first #define s second #define all(x) x.begin(), x.end() #define D(x) cerr << #x << " is " << (x) << "\n"; using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key() template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; } template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;} template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;} template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;} template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;} //9:20 const int N=6e4+1,M=6e5+1; vector<int> degree(N),visited(N); vector<set<pair<int,int> > > graf(N); int dif,n,k,a,b,c; void dfs(int tr) { if(graf[tr].size()==0) return; int sl=(*graf[tr].begin()).f; int t=(*graf[tr].begin()).s; graf[tr].erase(graf[tr].begin()); graf[sl].erase({tr,t}); if(tr<n) dif+=t; else dif-=t; dfs(sl); } bitset<2*M> moze; int main() { //freopen("tug1a.in","r",stdin); scanf("%i %i",&n,&k); for(int i=0;i<2*n;i++) scanf("%i %i %i",&a,&b,&c),a--,b+=n-1,graf[a].insert({b,c}),graf[b].insert({a,c}),degree[a]++,degree[b]++; queue<int> q; for(int i=0;i<2*n;i++) if(degree[i]==1) q.push(i); while(q.size()) { int tr=q.front(); q.pop(); visited[tr]=1; int sl=(*graf[tr].begin()).f; int t=(*graf[tr].begin()).s; graf[tr].erase(graf[tr].begin()); degree[tr]--; degree[sl]--; graf[sl].erase({tr,t}); if(degree[sl]==1) q.push(sl); if(tr<n) dif+=t; else dif-=t; } vector<int> dp={abs(dif)}; dif=0; for(int i=0;i<2*n;i++) { if(!visited[i]) { if(degree[i]==0) { printf("NO\n"); return 0; } assert(degree[i]==2); dfs(i); dp.pb(abs(dif)); dif=0; } } sort(dp.rbegin(),dp.rend()); while(dp.size()&&dp.back()==0) dp.pop_back(); if(dp.empty()) { printf("YES\n"); return 0; } moze[M]=1; for(auto p:dp) moze=(moze<<p)|(moze>>p); bool ima=false; for(int i=M;i<=M+k;i++) if(moze[i]) ima=true; if(ima) printf("YES\n"); else printf("NO\n"); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

tug.cpp: In function 'int main()':
tug.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&k);
  ~~~~~^~~~~~~~~~~~~~~
tug.cpp:52:102: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i %i %i",&a,&b,&c),a--,b+=n-1,graf[a].insert({b,c}),graf[b].insert({a,c}),degree[a]++,degree[b]++;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...