Submission #885119

# Submission time Handle Problem Language Result Execution time Memory
885119 2023-12-09T03:03:40 Z 12345678 Pipes (BOI13_pipes) C++17
74.0741 / 100
141 ms 59732 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int nx=5e5+5;
int n, m, h[nx], u, v, sz, res[nx], vs[nx], lvl[nx], f;
vector<pair<int, int>> d[nx];

void dfs(int u, int p, int idx)
{
    vs[u]=1; lvl[u]=lvl[p]+1;
    for (auto [v, id]:d[u]) 
    {
        if (v==p) continue;
        if (!vs[v]) dfs(v, u, id);
        else if ((lvl[u]-lvl[v]+1)%2==0) f=1;
    }
    if (idx==-1) return;
    res[idx]=2*h[u];
    h[p]-=h[u];
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m;
    for (int i=1; i<=n; i++) cin>>h[i];
    for (int i=1; i<=m; i++) cin>>u>>v, d[u].push_back({v, i}), d[v].push_back({u, i});
    dfs(1, 1, -1);
    if (m>n||f)
    {
        cout<<0;
        return 0;
    }
    if (m==n)cout<<1/0;
    for (int i=1; i<n; i++) cout<<res[i]<<'\n';
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:37:21: warning: division by zero [-Wdiv-by-zero]
   37 |     if (m==n)cout<<1/0;
      |                    ~^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 19036 KB Output is correct
2 Correct 3 ms 19036 KB Output is correct
3 Correct 4 ms 19036 KB Output is correct
4 Correct 38 ms 23124 KB Output is correct
5 Correct 3 ms 19036 KB Output is correct
6 Correct 3 ms 19036 KB Output is correct
7 Correct 3 ms 19036 KB Output is correct
8 Correct 3 ms 19036 KB Output is correct
9 Correct 4 ms 19148 KB Output is correct
10 Correct 4 ms 19104 KB Output is correct
11 Correct 4 ms 19036 KB Output is correct
12 Correct 4 ms 19036 KB Output is correct
13 Correct 34 ms 22352 KB Output is correct
14 Correct 41 ms 22872 KB Output is correct
15 Correct 43 ms 23048 KB Output is correct
16 Correct 34 ms 22612 KB Output is correct
17 Correct 39 ms 23124 KB Output is correct
18 Correct 40 ms 23132 KB Output is correct
19 Correct 42 ms 26452 KB Output is correct
20 Correct 3 ms 19036 KB Output is correct
21 Correct 4 ms 19036 KB Output is correct
22 Correct 41 ms 23228 KB Output is correct
23 Correct 30 ms 22408 KB Output is correct
24 Correct 40 ms 23124 KB Output is correct
25 Correct 33 ms 22356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 38236 KB Execution killed with signal 4
2 Runtime error 20 ms 38412 KB Execution killed with signal 4
3 Correct 34 ms 25680 KB Output is correct
4 Correct 41 ms 28496 KB Output is correct
5 Correct 37 ms 22576 KB Output is correct
6 Correct 131 ms 39252 KB Output is correct
7 Runtime error 17 ms 38236 KB Execution killed with signal 4
8 Runtime error 17 ms 38236 KB Execution killed with signal 4
9 Correct 3 ms 19068 KB Output is correct
10 Correct 3 ms 19288 KB Output is correct
11 Correct 3 ms 19036 KB Output is correct
12 Correct 3 ms 19036 KB Output is correct
13 Correct 3 ms 19032 KB Output is correct
14 Runtime error 17 ms 38176 KB Execution killed with signal 4
15 Runtime error 18 ms 38516 KB Execution killed with signal 4
16 Runtime error 18 ms 38492 KB Execution killed with signal 4
17 Correct 4 ms 19036 KB Output is correct
18 Correct 3 ms 19036 KB Output is correct
19 Correct 3 ms 19036 KB Output is correct
20 Correct 3 ms 19036 KB Output is correct
21 Correct 4 ms 19036 KB Output is correct
22 Runtime error 17 ms 38344 KB Execution killed with signal 4
23 Runtime error 46 ms 52052 KB Execution killed with signal 4
24 Runtime error 51 ms 53524 KB Execution killed with signal 4
25 Correct 34 ms 25688 KB Output is correct
26 Correct 36 ms 27500 KB Output is correct
27 Correct 38 ms 27848 KB Output is correct
28 Correct 35 ms 22736 KB Output is correct
29 Correct 108 ms 36552 KB Output is correct
30 Runtime error 56 ms 58468 KB Execution killed with signal 4
31 Runtime error 59 ms 58704 KB Execution killed with signal 4
32 Runtime error 50 ms 48360 KB Execution killed with signal 4
33 Correct 35 ms 26724 KB Output is correct
34 Correct 37 ms 26708 KB Output is correct
35 Correct 38 ms 28252 KB Output is correct
36 Correct 33 ms 22608 KB Output is correct
37 Correct 141 ms 39748 KB Output is correct
38 Runtime error 57 ms 56660 KB Execution killed with signal 4
39 Runtime error 49 ms 47440 KB Execution killed with signal 4
40 Runtime error 51 ms 52820 KB Execution killed with signal 4
41 Correct 38 ms 29008 KB Output is correct
42 Correct 47 ms 27216 KB Output is correct
43 Correct 37 ms 28436 KB Output is correct
44 Correct 40 ms 22704 KB Output is correct
45 Correct 101 ms 34964 KB Output is correct
46 Runtime error 57 ms 59732 KB Execution killed with signal 4
47 Runtime error 51 ms 53212 KB Execution killed with signal 4
48 Runtime error 56 ms 58088 KB Execution killed with signal 4
49 Correct 31 ms 23636 KB Output is correct
50 Correct 36 ms 26632 KB Output is correct
51 Correct 36 ms 24924 KB Output is correct
52 Correct 34 ms 24144 KB Output is correct
53 Correct 105 ms 35664 KB Output is correct
54 Runtime error 55 ms 55544 KB Execution killed with signal 4