# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
94373 | gumball | Pipes (BOI13_pipes) | C++14 | 139 ms | 16820 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n,m,i,a[101010],h[505050],ta,tb;
vector<ll> v[101010],w[101010];
ll dfs(ll aa,ll bb,ll cc)
{
ll ii;
for(ii=0;ii<v[aa].size();ii++)
{
if(w[aa][ii]==bb)continue;
dfs(v[aa][ii],w[aa][ii],aa);
}
if(aa==1)
{
if(a[aa]!=0)
{
cout<<0<<"\n";
exit(0);
}
}
else
{
h[bb]=a[aa]*2;
a[cc]-=a[aa];
a[aa]-=0;
}
}
int main()
{
ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
cin>>n>>m;
if(m>=n)
{
cout<<0<<"\n";
return 0;
}
for(i=1;i<=n;i++)cin>>a[i];
for(i=1;i<=m;i++)
{
cin>>ta>>tb;
v[ta].pb(tb);
v[tb].pb(ta);
w[ta].pb(i);
w[tb].pb(i);
}
dfs(1,0,0);
for(i=1;i<=m;i++)cout<<h[i]<<"\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |