Submission #855003

# Submission time Handle Problem Language Result Execution time Memory
855003 2023-09-29T18:23:23 Z hariaakas646 Pipes (BOI13_pipes) C++17
74.0741 / 100
100 ms 17020 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;

void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}


int main() {
    // usaco();
    int n, m;
    scd(n);
    scd(m);
    vll vec(n+1);

    forr(i, 1, n+1) sclld(vec[i]);
    if(m > n) {
        printf("0");
        return 0;
    }
    vector<set<pii>> graph(n+1);
    vi deg(n+1);
    frange(i, m) {
        int a, b;
        scd(a);
        scd(b);
        graph[a].insert(mp(b, i));
        graph[b].insert(mp(a, i));
        deg[a]++;
        deg[b]++;
    }
    vll out(m);
    queue<int> q;
    forr(i, 1, n+1) {
        if(deg[i] == 1) q.push(i);
    }

    vb cyc(n+1, true);
    vb vis(n+1);
    while(q.size()) {
        auto x = q.front();
        q.pop();
        cyc[x] = false;
        vis[x] = true;
        for(auto p : graph[x]) {
            graph[p.f].erase(mp(x, p.s));
            deg[p.f]--;
            out[p.s] = 2*vec[x];
            vec[p.f] -= vec[x];
            if(deg[p.f] == 1) q.push(p.f);
        }
    }
    int c = 0;
    forr(i, 1, n+1) {
        if(cyc[i]) c++;
    }
    if(c > 0 && c % 2==0) {
        printf("0");
        return 0;
    }
    forr(i, 1, n+1) {
        if(cyc[i]) {
            pii p = (*graph[i].begin());
            int x = p.f;
            int ed = p.s;
            lli k = 0;
            while(x != i) {
                k = vec[x] - k;
                x = (*graph[x].begin()).f;
            }
            lli v = (vec[i] - k)/2;
            out[ed] = 2 * v;
            x = (*graph[i].begin()).f;
            while(x != i) {
                v = vec[x] - v;
                pii p = *graph[x].begin();
                out[p.s] = 2*v;
                x = p.f;
            }
            break;
        }
    }
    frange(i, m) printf("%lld\n", out[i]);
}

Compilation message

pipes.cpp: In function 'void usaco()':
pipes.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
pipes.cpp:37:5: note: in expansion of macro 'scd'
   37 |     scd(n);
      |     ^~~
pipes.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
pipes.cpp:38:5: note: in expansion of macro 'scd'
   38 |     scd(m);
      |     ^~~
pipes.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | #define sclld(t) scanf("%lld", &t)
      |                  ~~~~~^~~~~~~~~~~~
pipes.cpp:41:21: note: in expansion of macro 'sclld'
   41 |     forr(i, 1, n+1) sclld(vec[i]);
      |                     ^~~~~
pipes.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
pipes.cpp:50:9: note: in expansion of macro 'scd'
   50 |         scd(a);
      |         ^~~
pipes.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
pipes.cpp:51:9: note: in expansion of macro 'scd'
   51 |         scd(b);
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 72 ms 16896 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 50 ms 13628 KB Output is correct
14 Correct 64 ms 15952 KB Output is correct
15 Correct 100 ms 17020 KB Output is correct
16 Correct 53 ms 14420 KB Output is correct
17 Correct 81 ms 16980 KB Output is correct
18 Correct 68 ms 16976 KB Output is correct
19 Correct 59 ms 16772 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 86 ms 16984 KB Output is correct
23 Correct 51 ms 13648 KB Output is correct
24 Correct 78 ms 16976 KB Output is correct
25 Correct 52 ms 14164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Correct 46 ms 15456 KB Output is correct
4 Correct 7 ms 1116 KB Output is correct
5 Correct 7 ms 1116 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Incorrect 0 ms 348 KB Output isn't correct
15 Incorrect 1 ms 348 KB Output isn't correct
16 Incorrect 1 ms 348 KB Output isn't correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Incorrect 1 ms 348 KB Output isn't correct
23 Incorrect 43 ms 13684 KB Output isn't correct
24 Incorrect 63 ms 16664 KB Output isn't correct
25 Correct 49 ms 15452 KB Output is correct
26 Correct 7 ms 1116 KB Output is correct
27 Correct 7 ms 1220 KB Output is correct
28 Correct 8 ms 1116 KB Output is correct
29 Correct 7 ms 1116 KB Output is correct
30 Incorrect 59 ms 16380 KB Output isn't correct
31 Incorrect 54 ms 16976 KB Output isn't correct
32 Incorrect 67 ms 16940 KB Output isn't correct
33 Correct 68 ms 16468 KB Output is correct
34 Correct 8 ms 1112 KB Output is correct
35 Correct 7 ms 1232 KB Output is correct
36 Correct 7 ms 1116 KB Output is correct
37 Correct 8 ms 1116 KB Output is correct
38 Incorrect 56 ms 16704 KB Output isn't correct
39 Incorrect 94 ms 16724 KB Output isn't correct
40 Incorrect 58 ms 16720 KB Output isn't correct
41 Correct 61 ms 16356 KB Output is correct
42 Correct 10 ms 1116 KB Output is correct
43 Correct 8 ms 1116 KB Output is correct
44 Correct 9 ms 1116 KB Output is correct
45 Correct 4 ms 604 KB Output is correct
46 Incorrect 56 ms 16724 KB Output isn't correct
47 Incorrect 56 ms 16720 KB Output isn't correct
48 Incorrect 50 ms 16532 KB Output isn't correct
49 Correct 57 ms 15704 KB Output is correct
50 Correct 8 ms 1112 KB Output is correct
51 Correct 7 ms 1112 KB Output is correct
52 Correct 7 ms 1116 KB Output is correct
53 Correct 5 ms 860 KB Output is correct
54 Incorrect 56 ms 16644 KB Output isn't correct