# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
107057 | 2019-04-21T15:48:54 Z | Pajaraja | Pipes (BOI13_pipes) | C++17 | 399 ms | 132096 KB |
#include <bits/stdc++.h> #define MAXN 100007 #define MAXM 500007 using namespace std; map<pair<int,int>,long long> mp; vector<int> g[MAXN],c; int gr[MAXM][2],n,m,deg[MAXN],parc[MAXN]; long long t[MAXN]; bool vi[MAXN]; void dfs(int s) { c.push_back(s); for(int i=0;i<g[s].size();i++) if(!vi[g[s][i]]) dfs(g[s][i]); } int main() { int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%lld",&t[i]); for(int i=0;i<m;i++) { scanf("%d%d",&gr[i][0],&gr[i][1]); g[gr[i][0]].push_back(gr[i][1]); g[gr[i][1]].push_back(gr[i][0]); } queue<int> q; for(int i=1;i<=n;i++) deg[i]=g[i].size(); for(int i=1;i<=n;i++) if(deg[i]==1) q.push(i); while(!q.empty()) { int u=q.front(); q.pop(); vi[u]=true; for(int i=0;i<g[u].size();i++) if(!vi[g[u][i]]) { deg[g[u][i]]--; t[g[u][i]]-=t[u]; mp[make_pair(u,g[u][i])]=mp[make_pair(g[u][i],u)]=2*t[u]; if(deg[g[u][i]]==1) q.push(g[u][i]); } } for(int i=1;i<=n;i++) if(deg[i]>2) {printf("0"); return 0;} for(int i=1;i<=n;i++) if(!vi[i]) { c.clear(); dfs(i); if(c.size()%2==0) {printf("0"); return 0;} long long tz=0; for(int i=0;i<c.size();i++) tz+=t[i]; tz/=2; for(int i=2;i<c.size();i+=2) parc[i]=parc[i-2]+t[c[i-2]]; parc[1]=parc[c.size()-1]+t[c[c.size()-1]]-tz; for(int i=3;i<c.size();i+=2) parc[i]=parc[i-2]+t[c[i-2]]; for(int i=0;i<c.size()-1;i++) mp[make_pair(c[i],c[i+1])]=mp[make_pair(c[i+1],c[i])]=2*(parc[i+1]-parc[i]); mp[make_pair(c[0],c[c.size()-1])]=mp[make_pair(c[c.size()-1],c[0])]=2*(tz-parc[c.size()-1]); } for(int i=0;i<m;i++) printf("%lld\n",mp[make_pair(gr[i][0],gr[i][1])]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2688 KB | Output is correct |
2 | Correct | 4 ms | 2688 KB | Output is correct |
3 | Correct | 6 ms | 2944 KB | Output is correct |
4 | Correct | 320 ms | 20988 KB | Output is correct |
5 | Correct | 5 ms | 2688 KB | Output is correct |
6 | Correct | 5 ms | 2688 KB | Output is correct |
7 | Correct | 4 ms | 2688 KB | Output is correct |
8 | Correct | 5 ms | 2688 KB | Output is correct |
9 | Correct | 8 ms | 2944 KB | Output is correct |
10 | Correct | 6 ms | 2816 KB | Output is correct |
11 | Correct | 7 ms | 2816 KB | Output is correct |
12 | Correct | 5 ms | 2944 KB | Output is correct |
13 | Correct | 277 ms | 17272 KB | Output is correct |
14 | Correct | 326 ms | 19960 KB | Output is correct |
15 | Correct | 357 ms | 21240 KB | Output is correct |
16 | Correct | 292 ms | 18168 KB | Output is correct |
17 | Correct | 399 ms | 20856 KB | Output is correct |
18 | Correct | 303 ms | 20984 KB | Output is correct |
19 | Correct | 285 ms | 20856 KB | Output is correct |
20 | Correct | 5 ms | 2688 KB | Output is correct |
21 | Correct | 6 ms | 2944 KB | Output is correct |
22 | Correct | 351 ms | 21036 KB | Output is correct |
23 | Correct | 270 ms | 17244 KB | Output is correct |
24 | Correct | 361 ms | 21240 KB | Output is correct |
25 | Correct | 226 ms | 17976 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 147 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Runtime error | 139 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
3 | Runtime error | 284 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
4 | Correct | 110 ms | 10744 KB | Output is correct |
5 | Correct | 213 ms | 16632 KB | Output is correct |
6 | Correct | 333 ms | 15776 KB | Output is correct |
7 | Runtime error | 153 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
8 | Runtime error | 137 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
9 | Runtime error | 142 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
10 | Correct | 4 ms | 2688 KB | Output is correct |
11 | Correct | 4 ms | 2688 KB | Output is correct |
12 | Correct | 4 ms | 2688 KB | Output is correct |
13 | Correct | 4 ms | 2688 KB | Output is correct |
14 | Runtime error | 155 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
15 | Runtime error | 161 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
16 | Runtime error | 156 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
17 | Runtime error | 152 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
18 | Correct | 5 ms | 2816 KB | Output is correct |
19 | Correct | 5 ms | 2816 KB | Output is correct |
20 | Correct | 5 ms | 2816 KB | Output is correct |
21 | Correct | 6 ms | 2816 KB | Output is correct |
22 | Runtime error | 146 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
23 | Runtime error | 253 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
24 | Runtime error | 240 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
25 | Runtime error | 232 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
26 | Correct | 96 ms | 11512 KB | Output is correct |
27 | Correct | 81 ms | 8952 KB | Output is correct |
28 | Correct | 151 ms | 14840 KB | Output is correct |
29 | Correct | 266 ms | 13640 KB | Output is correct |
30 | Runtime error | 278 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
31 | Runtime error | 225 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
32 | Runtime error | 363 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
33 | Runtime error | 272 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
34 | Correct | 117 ms | 10360 KB | Output is correct |
35 | Correct | 109 ms | 10744 KB | Output is correct |
36 | Correct | 185 ms | 15736 KB | Output is correct |
37 | Correct | 323 ms | 15792 KB | Output is correct |
38 | Runtime error | 276 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
39 | Runtime error | 382 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
40 | Runtime error | 297 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
41 | Runtime error | 231 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
42 | Correct | 89 ms | 8184 KB | Output is correct |
43 | Correct | 84 ms | 8236 KB | Output is correct |
44 | Correct | 229 ms | 16560 KB | Output is correct |
45 | Correct | 226 ms | 13432 KB | Output is correct |
46 | Runtime error | 303 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
47 | Runtime error | 298 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
48 | Runtime error | 249 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
49 | Runtime error | 372 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
50 | Correct | 141 ms | 12408 KB | Output is correct |
51 | Correct | 207 ms | 14460 KB | Output is correct |
52 | Correct | 105 ms | 10460 KB | Output is correct |
53 | Correct | 228 ms | 13824 KB | Output is correct |
54 | Runtime error | 284 ms | 132096 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |