# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
90619 |
2018-12-23T00:08:39 Z |
psmao |
Pipes (BOI13_pipes) |
C++14 |
|
108 ms |
9588 KB |
#include <bits/stdc++.h>
using namespace std;
#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#ifdef MPS
#define D(x...) printf(x)
#else
#define D(x...)
#endif
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;
void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}
const int maxn = 100050;
int n, m, deg[maxn], s[maxn];
ll v[maxn];
vector<pii> adj[maxn];
queue<int> Q;
VI pathx, nodex;
bool vis[maxn];
int main()
{
#ifdef MPS
fp("1.in","r",stdin);
fp("1.out","w",stdout);
#endif
sf("%d%d",&n,&m);
if(m != n-1 && m != n) return 0 * pf("0\n");
fo(i,1,n) sf("%d",&s[i]);
fo(i,1,m)
{
int u, v; sf("%d%d",&u,&v);
adj[u].pb(mp(v,i));
adj[v].pb(mp(u,i));
deg[u] ++; deg[v] ++;
}
fo(i,1,n) if(deg[i] == 1) Q.push(i);
while(!Q.empty())
{
int h = Q.front(); Q.pop();
vis[h] = true;
for(auto p : adj[h]) if(!vis[p.fi])
{
v[p.se] = s[h];
s[p.fi] -= s[h];
if((--deg[p.fi]) == 1) Q.push(p.fi);
}
}
fo(i,1,n) if(deg[i] == 2)
{
int x = i; ll cur = 0ll;
while(1)
{
bool contin = false; deg[x] --;
cur = s[x] - cur; nodex.pb(x);
for(auto p : adj[x]) if(deg[p.fi] == 2) {x = p.fi; pathx.pb(p.se); contin = true; break;}
if(!contin) // we have iterated the cycle already
{
if(!(SZ(nodex)&1)) return 0 * pf("0\n");
for(auto p : adj[x]) if(p.fi == i) {pathx.pb(p.se); break;}
if(cur&1) return 0 * pf("0\n");
cur >>= 1;
v[pathx.back()] = cur;
for(int p = 0; p < SZ(pathx)-1; ++ p) {cur = s[nodex[p]] - cur; v[pathx[p]] = cur;}
break;
}
}
break;
}
fo(i,1,m) pf("%lld\n", v[i]*2);
return 0;
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:48:4: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
sf("%d%d",&n,&m);
^
pipes.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fo(i,1,n) sf("%d",&s[i]);
^
pipes.cpp:53:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int u, v; sf("%d%d",&u,&v);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
3 |
Correct |
4 ms |
2864 KB |
Output is correct |
4 |
Correct |
97 ms |
9064 KB |
Output is correct |
5 |
Correct |
4 ms |
9064 KB |
Output is correct |
6 |
Correct |
4 ms |
9064 KB |
Output is correct |
7 |
Correct |
5 ms |
9064 KB |
Output is correct |
8 |
Correct |
4 ms |
9064 KB |
Output is correct |
9 |
Correct |
4 ms |
9064 KB |
Output is correct |
10 |
Correct |
4 ms |
9064 KB |
Output is correct |
11 |
Correct |
4 ms |
9064 KB |
Output is correct |
12 |
Correct |
4 ms |
9064 KB |
Output is correct |
13 |
Correct |
68 ms |
9064 KB |
Output is correct |
14 |
Correct |
70 ms |
9064 KB |
Output is correct |
15 |
Correct |
76 ms |
9312 KB |
Output is correct |
16 |
Correct |
58 ms |
9312 KB |
Output is correct |
17 |
Correct |
68 ms |
9312 KB |
Output is correct |
18 |
Correct |
73 ms |
9312 KB |
Output is correct |
19 |
Correct |
74 ms |
9312 KB |
Output is correct |
20 |
Correct |
4 ms |
9312 KB |
Output is correct |
21 |
Correct |
5 ms |
9312 KB |
Output is correct |
22 |
Correct |
93 ms |
9344 KB |
Output is correct |
23 |
Correct |
68 ms |
9344 KB |
Output is correct |
24 |
Correct |
75 ms |
9344 KB |
Output is correct |
25 |
Correct |
72 ms |
9344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9344 KB |
Output is correct |
2 |
Correct |
4 ms |
9344 KB |
Output is correct |
3 |
Correct |
89 ms |
9344 KB |
Output is correct |
4 |
Correct |
3 ms |
9344 KB |
Output is correct |
5 |
Correct |
3 ms |
9344 KB |
Output is correct |
6 |
Correct |
3 ms |
9344 KB |
Output is correct |
7 |
Correct |
4 ms |
9344 KB |
Output is correct |
8 |
Correct |
3 ms |
9344 KB |
Output is correct |
9 |
Correct |
3 ms |
9344 KB |
Output is correct |
10 |
Correct |
4 ms |
9344 KB |
Output is correct |
11 |
Correct |
3 ms |
9344 KB |
Output is correct |
12 |
Correct |
4 ms |
9344 KB |
Output is correct |
13 |
Correct |
4 ms |
9344 KB |
Output is correct |
14 |
Correct |
3 ms |
9344 KB |
Output is correct |
15 |
Correct |
4 ms |
9344 KB |
Output is correct |
16 |
Correct |
5 ms |
9344 KB |
Output is correct |
17 |
Correct |
4 ms |
9344 KB |
Output is correct |
18 |
Correct |
4 ms |
9344 KB |
Output is correct |
19 |
Correct |
4 ms |
9344 KB |
Output is correct |
20 |
Correct |
3 ms |
9344 KB |
Output is correct |
21 |
Correct |
3 ms |
9344 KB |
Output is correct |
22 |
Correct |
4 ms |
9344 KB |
Output is correct |
23 |
Correct |
78 ms |
9344 KB |
Output is correct |
24 |
Correct |
79 ms |
9500 KB |
Output is correct |
25 |
Correct |
87 ms |
9500 KB |
Output is correct |
26 |
Correct |
4 ms |
9500 KB |
Output is correct |
27 |
Correct |
3 ms |
9500 KB |
Output is correct |
28 |
Correct |
3 ms |
9500 KB |
Output is correct |
29 |
Correct |
3 ms |
9500 KB |
Output is correct |
30 |
Correct |
102 ms |
9500 KB |
Output is correct |
31 |
Correct |
108 ms |
9500 KB |
Output is correct |
32 |
Correct |
93 ms |
9500 KB |
Output is correct |
33 |
Correct |
98 ms |
9500 KB |
Output is correct |
34 |
Correct |
4 ms |
9500 KB |
Output is correct |
35 |
Correct |
4 ms |
9500 KB |
Output is correct |
36 |
Correct |
4 ms |
9500 KB |
Output is correct |
37 |
Correct |
4 ms |
9500 KB |
Output is correct |
38 |
Correct |
106 ms |
9500 KB |
Output is correct |
39 |
Correct |
97 ms |
9500 KB |
Output is correct |
40 |
Correct |
99 ms |
9500 KB |
Output is correct |
41 |
Correct |
101 ms |
9500 KB |
Output is correct |
42 |
Correct |
4 ms |
9500 KB |
Output is correct |
43 |
Correct |
4 ms |
9500 KB |
Output is correct |
44 |
Correct |
3 ms |
9500 KB |
Output is correct |
45 |
Correct |
3 ms |
9500 KB |
Output is correct |
46 |
Correct |
86 ms |
9500 KB |
Output is correct |
47 |
Correct |
85 ms |
9500 KB |
Output is correct |
48 |
Correct |
86 ms |
9588 KB |
Output is correct |
49 |
Correct |
65 ms |
9588 KB |
Output is correct |
50 |
Correct |
3 ms |
9588 KB |
Output is correct |
51 |
Correct |
3 ms |
9588 KB |
Output is correct |
52 |
Correct |
3 ms |
9588 KB |
Output is correct |
53 |
Correct |
3 ms |
9588 KB |
Output is correct |
54 |
Correct |
77 ms |
9588 KB |
Output is correct |