# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
26388 | samir_droubi | Pipes (BOI13_pipes) | C++14 | 676 ms | 55916 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>
using namespace std;
int n,m;
const int mxn=(1e5)+5;
int c[mxn];
set<pair<int,int> > s;
set<pair<int,int> >gr[mxn];
int ans[mxn*5];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)
scanf("%d",&c[i]);
for(int i=1;i<=m;++i)
{
int x,y;
scanf("%d%d",&x,&y);
gr[x].insert({y,i});
gr[y].insert({x,i});
}
if(m>=n)
{
puts("0");
return 0;
}
for(int i=1;i<=n;++i)
s.insert({gr[i].size(),i});
while(!s.empty())
{
int v=s.begin()->second;
int u=gr[v].begin()->first;
int in=gr[v].begin()->second;
s.erase(s.begin());
gr[u].erase({v,in});
ans[in]=2*c[v];
c[u]-=c[v];
}
for(int i=1;i<=m;++i)printf("%d\n",ans[i]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |