# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
107055 | 2019-04-21T15:44:29 Z | Pajaraja | Pipes (BOI13_pipes) | C++17 | 400 ms | 22648 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]>1) {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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 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 | 22520 KB | Output is correct |
5 | Correct | 4 ms | 2688 KB | Output is correct |
6 | Correct | 4 ms | 2688 KB | Output is correct |
7 | Correct | 5 ms | 2688 KB | Output is correct |
8 | Correct | 4 ms | 2688 KB | Output is correct |
9 | Correct | 6 ms | 2944 KB | Output is correct |
10 | Correct | 6 ms | 2944 KB | Output is correct |
11 | Correct | 6 ms | 2944 KB | Output is correct |
12 | Correct | 6 ms | 2944 KB | Output is correct |
13 | Correct | 254 ms | 18424 KB | Output is correct |
14 | Correct | 299 ms | 21548 KB | Output is correct |
15 | Correct | 305 ms | 22648 KB | Output is correct |
16 | Correct | 259 ms | 19580 KB | Output is correct |
17 | Correct | 303 ms | 22552 KB | Output is correct |
18 | Correct | 320 ms | 22648 KB | Output is correct |
19 | Correct | 290 ms | 22520 KB | Output is correct |
20 | Correct | 4 ms | 2688 KB | Output is correct |
21 | Correct | 5 ms | 2944 KB | Output is correct |
22 | Correct | 322 ms | 22608 KB | Output is correct |
23 | Correct | 211 ms | 18496 KB | Output is correct |
24 | Correct | 400 ms | 22648 KB | Output is correct |
25 | Correct | 259 ms | 19396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 2688 KB | Output isn't correct |
2 | Incorrect | 6 ms | 2816 KB | Output isn't correct |
3 | Correct | 157 ms | 15344 KB | Output is correct |
4 | Correct | 111 ms | 12272 KB | Output is correct |
5 | Correct | 189 ms | 18296 KB | Output is correct |
6 | Correct | 268 ms | 22068 KB | Output is correct |
7 | Incorrect | 5 ms | 2688 KB | Output isn't correct |
8 | Incorrect | 4 ms | 2688 KB | Output isn't correct |
9 | Correct | 5 ms | 2688 KB | Output is correct |
10 | Correct | 5 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 | 5 ms | 2688 KB | Output is correct |
14 | Incorrect | 5 ms | 2688 KB | Output isn't correct |
15 | Incorrect | 6 ms | 2808 KB | Output isn't correct |
16 | Incorrect | 5 ms | 2816 KB | Output isn't correct |
17 | Correct | 5 ms | 2816 KB | Output is correct |
18 | Correct | 6 ms | 2816 KB | Output is correct |
19 | Correct | 7 ms | 2816 KB | Output is correct |
20 | Correct | 5 ms | 2688 KB | Output is correct |
21 | Correct | 5 ms | 2816 KB | Output is correct |
22 | Incorrect | 6 ms | 2816 KB | Output isn't correct |
23 | Incorrect | 105 ms | 11872 KB | Output isn't correct |
24 | Incorrect | 171 ms | 15532 KB | Output isn't correct |
25 | Correct | 170 ms | 15428 KB | Output is correct |
26 | Correct | 111 ms | 13176 KB | Output is correct |
27 | Correct | 88 ms | 10532 KB | Output is correct |
28 | Correct | 186 ms | 16504 KB | Output is correct |
29 | Correct | 256 ms | 18816 KB | Output is correct |
30 | Incorrect | 183 ms | 16172 KB | Output isn't correct |
31 | Incorrect | 83 ms | 11216 KB | Output isn't correct |
32 | Incorrect | 286 ms | 20056 KB | Output isn't correct |
33 | Correct | 156 ms | 15320 KB | Output is correct |
34 | Correct | 102 ms | 12024 KB | Output is correct |
35 | Correct | 119 ms | 12280 KB | Output is correct |
36 | Correct | 213 ms | 17192 KB | Output is correct |
37 | Correct | 330 ms | 21976 KB | Output is correct |
38 | Incorrect | 160 ms | 16248 KB | Output isn't correct |
39 | Incorrect | 285 ms | 20708 KB | Output isn't correct |
40 | Incorrect | 193 ms | 16248 KB | Output isn't correct |
41 | Correct | 93 ms | 11128 KB | Output is correct |
42 | Correct | 79 ms | 9820 KB | Output is correct |
43 | Correct | 69 ms | 9848 KB | Output is correct |
44 | Correct | 229 ms | 18192 KB | Output is correct |
45 | Correct | 273 ms | 18808 KB | Output is correct |
46 | Incorrect | 195 ms | 16888 KB | Output isn't correct |
47 | Incorrect | 168 ms | 15940 KB | Output isn't correct |
48 | Incorrect | 106 ms | 11512 KB | Output isn't correct |
49 | Correct | 214 ms | 19164 KB | Output is correct |
50 | Correct | 155 ms | 14072 KB | Output is correct |
51 | Correct | 153 ms | 16112 KB | Output is correct |
52 | Correct | 95 ms | 12100 KB | Output is correct |
53 | Correct | 273 ms | 19296 KB | Output is correct |
54 | Incorrect | 189 ms | 17208 KB | Output isn't correct |