# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
127076 | 2019-07-08T21:12:37 Z | TadijaSebez | Tug of War (BOI15_tug) | C++11 | 3000 ms | 4700 KB |
#include <bits/stdc++.h> using namespace std; #define pb push_back const int N=60050; vector<pair<int,int>> E[N]; bool was[N]; int n,k; int sum[2],deg[N]; int main() { int u,v,w; scanf("%i %i",&n,&k); for(int i=1;i<=2*n;i++) { scanf("%i %i %i",&u,&v,&w); v+=n; E[u].pb({v,w}); E[v].pb({u,w}); deg[u]++; deg[v]++; } queue<int> q; for(int i=1;i<=2*n;i++) if(deg[i]==1) q.push(i),was[i]=1; while(q.size()) { int x=q.front(); q.pop(); int b=x>n; bool ok=0; for(auto e:E[x]) if(!was[e.first]) { ok=1; v=e.first; w=e.second; } if(!ok || deg[v]==1) return 0*printf("NO\n"); sum[b]+=w; deg[v]--; if(deg[v]==1) was[v]=1,q.push(v); } for(int i=1;i<=2*n;i++) if(!was[i] && deg[i]!=2) return 0*printf("NO\n"); vector<int> cyc; for(int i=1;i<=2*n;i++) if(!was[i]) { int all=0; int par=0; for(int x=i,t=1,y;;t=-t) { int w; was[x]=1; bool ok=0; for(auto e:E[x]) if(deg[e.first]==2 && e.first!=par) { y=e.first; w=e.second; ok=1; } if(!ok) { vector<int> ws; for(auto e:E[i]) if(deg[e.first]==2) ws.pb(e.second); all=ws[0]-ws[1]; break; } all+=t*w; par=x; x=y; if(x==i) break; } cyc.pb(all); } set<int> dp; dp.insert(sum[1]-sum[0]); for(int x:cyc) { vector<int> ins; for(int y:dp) { ins.pb(y+x); ins.pb(y-x); } dp.clear(); for(int y:ins) dp.insert(y); } int ans=1e9; for(int y:dp) ans=min(ans,abs(y)); if(ans<=k) printf("YES\n"); else printf("NO\n"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1784 KB | Output is correct |
2 | Correct | 3 ms | 1784 KB | Output is correct |
3 | Correct | 3 ms | 1784 KB | Output is correct |
4 | Correct | 3 ms | 1660 KB | Output is correct |
5 | Correct | 3 ms | 1784 KB | Output is correct |
6 | Correct | 3 ms | 1784 KB | Output is correct |
7 | Correct | 3 ms | 1784 KB | Output is correct |
8 | Correct | 3 ms | 1784 KB | Output is correct |
9 | Correct | 3 ms | 1656 KB | Output is correct |
10 | Correct | 3 ms | 1784 KB | Output is correct |
11 | Correct | 3 ms | 1656 KB | Output is correct |
12 | Correct | 3 ms | 1784 KB | Output is correct |
13 | Correct | 3 ms | 1784 KB | Output is correct |
14 | Correct | 3 ms | 1784 KB | Output is correct |
15 | Correct | 3 ms | 1784 KB | Output is correct |
16 | Correct | 3 ms | 1784 KB | Output is correct |
17 | Correct | 3 ms | 1788 KB | Output is correct |
18 | Correct | 3 ms | 1784 KB | Output is correct |
19 | Correct | 3 ms | 1656 KB | Output is correct |
20 | Correct | 3 ms | 1656 KB | Output is correct |
21 | Correct | 3 ms | 1784 KB | Output is correct |
22 | Correct | 3 ms | 1784 KB | Output is correct |
23 | Correct | 3 ms | 1784 KB | Output is correct |
24 | Correct | 3 ms | 1784 KB | Output is correct |
25 | Correct | 3 ms | 1784 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1784 KB | Output is correct |
2 | Correct | 3 ms | 1784 KB | Output is correct |
3 | Correct | 3 ms | 1784 KB | Output is correct |
4 | Correct | 3 ms | 1660 KB | Output is correct |
5 | Correct | 3 ms | 1784 KB | Output is correct |
6 | Correct | 3 ms | 1784 KB | Output is correct |
7 | Correct | 3 ms | 1784 KB | Output is correct |
8 | Correct | 3 ms | 1784 KB | Output is correct |
9 | Correct | 3 ms | 1656 KB | Output is correct |
10 | Correct | 3 ms | 1784 KB | Output is correct |
11 | Correct | 3 ms | 1656 KB | Output is correct |
12 | Correct | 3 ms | 1784 KB | Output is correct |
13 | Correct | 3 ms | 1784 KB | Output is correct |
14 | Correct | 3 ms | 1784 KB | Output is correct |
15 | Correct | 3 ms | 1784 KB | Output is correct |
16 | Correct | 3 ms | 1784 KB | Output is correct |
17 | Correct | 3 ms | 1788 KB | Output is correct |
18 | Correct | 3 ms | 1784 KB | Output is correct |
19 | Correct | 3 ms | 1656 KB | Output is correct |
20 | Correct | 3 ms | 1656 KB | Output is correct |
21 | Correct | 3 ms | 1784 KB | Output is correct |
22 | Correct | 3 ms | 1784 KB | Output is correct |
23 | Correct | 3 ms | 1784 KB | Output is correct |
24 | Correct | 3 ms | 1784 KB | Output is correct |
25 | Correct | 3 ms | 1784 KB | Output is correct |
26 | Correct | 2266 ms | 3288 KB | Output is correct |
27 | Correct | 1321 ms | 4532 KB | Output is correct |
28 | Correct | 2239 ms | 3224 KB | Output is correct |
29 | Correct | 1333 ms | 4680 KB | Output is correct |
30 | Correct | 2292 ms | 2984 KB | Output is correct |
31 | Correct | 1325 ms | 4700 KB | Output is correct |
32 | Correct | 2238 ms | 2896 KB | Output is correct |
33 | Correct | 1316 ms | 4536 KB | Output is correct |
34 | Correct | 191 ms | 3324 KB | Output is correct |
35 | Correct | 1360 ms | 4648 KB | Output is correct |
36 | Correct | 2310 ms | 3104 KB | Output is correct |
37 | Correct | 1291 ms | 4560 KB | Output is correct |
38 | Correct | 2343 ms | 3076 KB | Output is correct |
39 | Correct | 1367 ms | 4680 KB | Output is correct |
40 | Correct | 2281 ms | 3028 KB | Output is correct |
41 | Correct | 1321 ms | 4668 KB | Output is correct |
42 | Correct | 2461 ms | 3036 KB | Output is correct |
43 | Correct | 1338 ms | 4576 KB | Output is correct |
44 | Correct | 2389 ms | 3004 KB | Output is correct |
45 | Correct | 1347 ms | 4604 KB | Output is correct |
46 | Correct | 2253 ms | 3084 KB | Output is correct |
47 | Correct | 5 ms | 1912 KB | Output is correct |
48 | Correct | 455 ms | 2424 KB | Output is correct |
49 | Correct | 457 ms | 2408 KB | Output is correct |
50 | Execution timed out | 3041 ms | 3704 KB | Time limit exceeded |
51 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 2552 KB | Output is correct |
2 | Correct | 14 ms | 2808 KB | Output is correct |
3 | Correct | 16 ms | 2808 KB | Output is correct |
4 | Correct | 14 ms | 2808 KB | Output is correct |
5 | Correct | 18 ms | 2808 KB | Output is correct |
6 | Correct | 15 ms | 2808 KB | Output is correct |
7 | Correct | 16 ms | 2808 KB | Output is correct |
8 | Correct | 15 ms | 2800 KB | Output is correct |
9 | Correct | 16 ms | 2808 KB | Output is correct |
10 | Correct | 14 ms | 2780 KB | Output is correct |
11 | Correct | 16 ms | 2808 KB | Output is correct |
12 | Correct | 13 ms | 2808 KB | Output is correct |
13 | Correct | 16 ms | 2808 KB | Output is correct |
14 | Correct | 16 ms | 2808 KB | Output is correct |
15 | Correct | 13 ms | 2808 KB | Output is correct |
16 | Correct | 16 ms | 2808 KB | Output is correct |
17 | Correct | 14 ms | 2936 KB | Output is correct |
18 | Correct | 16 ms | 2800 KB | Output is correct |
19 | Correct | 14 ms | 2808 KB | Output is correct |
20 | Correct | 16 ms | 2808 KB | Output is correct |
21 | Correct | 14 ms | 2808 KB | Output is correct |
22 | Correct | 16 ms | 2936 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1784 KB | Output is correct |
2 | Correct | 3 ms | 1784 KB | Output is correct |
3 | Correct | 3 ms | 1784 KB | Output is correct |
4 | Correct | 3 ms | 1660 KB | Output is correct |
5 | Correct | 3 ms | 1784 KB | Output is correct |
6 | Correct | 3 ms | 1784 KB | Output is correct |
7 | Correct | 3 ms | 1784 KB | Output is correct |
8 | Correct | 3 ms | 1784 KB | Output is correct |
9 | Correct | 3 ms | 1656 KB | Output is correct |
10 | Correct | 3 ms | 1784 KB | Output is correct |
11 | Correct | 3 ms | 1656 KB | Output is correct |
12 | Correct | 3 ms | 1784 KB | Output is correct |
13 | Correct | 3 ms | 1784 KB | Output is correct |
14 | Correct | 3 ms | 1784 KB | Output is correct |
15 | Correct | 3 ms | 1784 KB | Output is correct |
16 | Correct | 3 ms | 1784 KB | Output is correct |
17 | Correct | 3 ms | 1788 KB | Output is correct |
18 | Correct | 3 ms | 1784 KB | Output is correct |
19 | Correct | 3 ms | 1656 KB | Output is correct |
20 | Correct | 3 ms | 1656 KB | Output is correct |
21 | Correct | 3 ms | 1784 KB | Output is correct |
22 | Correct | 3 ms | 1784 KB | Output is correct |
23 | Correct | 3 ms | 1784 KB | Output is correct |
24 | Correct | 3 ms | 1784 KB | Output is correct |
25 | Correct | 3 ms | 1784 KB | Output is correct |
26 | Correct | 2266 ms | 3288 KB | Output is correct |
27 | Correct | 1321 ms | 4532 KB | Output is correct |
28 | Correct | 2239 ms | 3224 KB | Output is correct |
29 | Correct | 1333 ms | 4680 KB | Output is correct |
30 | Correct | 2292 ms | 2984 KB | Output is correct |
31 | Correct | 1325 ms | 4700 KB | Output is correct |
32 | Correct | 2238 ms | 2896 KB | Output is correct |
33 | Correct | 1316 ms | 4536 KB | Output is correct |
34 | Correct | 191 ms | 3324 KB | Output is correct |
35 | Correct | 1360 ms | 4648 KB | Output is correct |
36 | Correct | 2310 ms | 3104 KB | Output is correct |
37 | Correct | 1291 ms | 4560 KB | Output is correct |
38 | Correct | 2343 ms | 3076 KB | Output is correct |
39 | Correct | 1367 ms | 4680 KB | Output is correct |
40 | Correct | 2281 ms | 3028 KB | Output is correct |
41 | Correct | 1321 ms | 4668 KB | Output is correct |
42 | Correct | 2461 ms | 3036 KB | Output is correct |
43 | Correct | 1338 ms | 4576 KB | Output is correct |
44 | Correct | 2389 ms | 3004 KB | Output is correct |
45 | Correct | 1347 ms | 4604 KB | Output is correct |
46 | Correct | 2253 ms | 3084 KB | Output is correct |
47 | Correct | 5 ms | 1912 KB | Output is correct |
48 | Correct | 455 ms | 2424 KB | Output is correct |
49 | Correct | 457 ms | 2408 KB | Output is correct |
50 | Execution timed out | 3041 ms | 3704 KB | Time limit exceeded |
51 | Halted | 0 ms | 0 KB | - |