Submission #285367

# Submission time Handle Problem Language Result Execution time Memory
285367 2020-08-28T20:20:06 Z ScarletS Pipes (BOI13_pipes) C++17
30 / 100
252 ms 23288 KB
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define f first
#define s second
using namespace std;

const int MAXN=1e5+10;
int n,m;
vector<pii> edges[MAXN];
int scores[MAXN], cur[MAXN], ans[5*MAXN];

void dfsTree(int c, int p, int x)
{
    for (pii i : edges[c])
        if (i.f!=p)
        {
            dfsTree(i.f,c,i.s);
            cur[c]+=ans[i.s];
        }
    if (c!=1)
    {
        ans[x]=scores[c]-cur[c];
        cur[c]+=ans[x];
    }
}

void treeCase()
{
    dfsTree(1,0,0);
    if (scores[1]!=cur[1])
    {
        cout<<"-1\n";
        return;
    }
    for (int i=0;i<m;++i)
        cout<<ans[i]*2<<"\n";
} 

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int u,v;
    cin>>n>>m;
    for (int i=1;i<=n;++i)
        cin>>scores[i];
    for (int i=0;i<m;++i)
    {
        cin>>u>>v;
        edges[u].push_back({v,i});
        edges[v].push_back({u,i});
    }
    if (m==n-1)
    {
        treeCase();
        return 0;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 3 ms 2816 KB Output is correct
4 Correct 67 ms 9592 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 3 ms 2816 KB Output is correct
10 Correct 2 ms 2816 KB Output is correct
11 Correct 2 ms 2816 KB Output is correct
12 Correct 3 ms 2816 KB Output is correct
13 Correct 62 ms 8244 KB Output is correct
14 Correct 64 ms 9208 KB Output is correct
15 Correct 67 ms 9592 KB Output is correct
16 Correct 67 ms 8572 KB Output is correct
17 Correct 69 ms 9592 KB Output is correct
18 Correct 71 ms 9596 KB Output is correct
19 Correct 80 ms 12920 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2816 KB Output is correct
22 Correct 71 ms 9592 KB Output is correct
23 Correct 68 ms 8184 KB Output is correct
24 Correct 81 ms 9592 KB Output is correct
25 Correct 66 ms 8440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2688 KB Output isn't correct
2 Incorrect 2 ms 2688 KB Output isn't correct
3 Incorrect 48 ms 7800 KB Output isn't correct
4 Incorrect 65 ms 7928 KB Output isn't correct
5 Incorrect 57 ms 8184 KB Output isn't correct
6 Incorrect 252 ms 23288 KB Output isn't correct
7 Incorrect 2 ms 2688 KB Output isn't correct
8 Incorrect 2 ms 2688 KB Output isn't correct
9 Incorrect 2 ms 2688 KB Output isn't correct
10 Incorrect 2 ms 2688 KB Output isn't correct
11 Incorrect 2 ms 2688 KB Output isn't correct
12 Incorrect 2 ms 2688 KB Output isn't correct
13 Incorrect 2 ms 2688 KB Output isn't correct
14 Incorrect 2 ms 2748 KB Output isn't correct
15 Incorrect 2 ms 2688 KB Output isn't correct
16 Incorrect 2 ms 2688 KB Output isn't correct
17 Incorrect 2 ms 2688 KB Output isn't correct
18 Incorrect 2 ms 2688 KB Output isn't correct
19 Incorrect 2 ms 2688 KB Output isn't correct
20 Incorrect 2 ms 2688 KB Output isn't correct
21 Incorrect 3 ms 2816 KB Output isn't correct
22 Incorrect 3 ms 2688 KB Output isn't correct
23 Incorrect 39 ms 7032 KB Output isn't correct
24 Incorrect 46 ms 8056 KB Output isn't correct
25 Incorrect 45 ms 7800 KB Output isn't correct
26 Incorrect 52 ms 8056 KB Output isn't correct
27 Incorrect 47 ms 7800 KB Output isn't correct
28 Incorrect 52 ms 8312 KB Output isn't correct
29 Incorrect 177 ms 19360 KB Output isn't correct
30 Incorrect 47 ms 7672 KB Output isn't correct
31 Incorrect 50 ms 7808 KB Output isn't correct
32 Incorrect 48 ms 8312 KB Output isn't correct
33 Incorrect 50 ms 8012 KB Output isn't correct
34 Incorrect 53 ms 7928 KB Output isn't correct
35 Incorrect 49 ms 7928 KB Output isn't correct
36 Incorrect 52 ms 8312 KB Output isn't correct
37 Incorrect 234 ms 23108 KB Output isn't correct
38 Incorrect 47 ms 7928 KB Output isn't correct
39 Incorrect 50 ms 8248 KB Output isn't correct
40 Incorrect 48 ms 8056 KB Output isn't correct
41 Incorrect 48 ms 7800 KB Output isn't correct
42 Incorrect 47 ms 7800 KB Output isn't correct
43 Incorrect 47 ms 7800 KB Output isn't correct
44 Incorrect 48 ms 8056 KB Output isn't correct
45 Incorrect 164 ms 20344 KB Output isn't correct
46 Incorrect 62 ms 7800 KB Output isn't correct
47 Incorrect 66 ms 8056 KB Output isn't correct
48 Incorrect 49 ms 7928 KB Output isn't correct
49 Incorrect 50 ms 8060 KB Output isn't correct
50 Incorrect 53 ms 7928 KB Output isn't correct
51 Incorrect 54 ms 8056 KB Output isn't correct
52 Incorrect 53 ms 7928 KB Output isn't correct
53 Incorrect 195 ms 20600 KB Output isn't correct
54 Incorrect 50 ms 7928 KB Output isn't correct