답안 #631400

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
631400 2022-08-18T05:32:17 Z socpite Pipes (BOI13_pipes) C++14
75.3704 / 100
182 ms 131072 KB
#include<bits/stdc++.h>
using namespace std;

#define f first
#define s second

const int mx = 1e7+5;
const int maxn = 1e5+5;

typedef long long ll;

ll lim = 1;

int _s, _t;

int n, m;
vector<int> idx, vert;

int vis[maxn], oncyc[maxn];
ll val[maxn], ans[maxn], A[maxn];
vector<pair<int, int>> graph[maxn];

void find_ep(int x, int p){
    vis[x]=1;
    for(auto v: graph[x]){
        if(v.f == p)continue;
        if(vis[v.f]){
            if(!_s){
                _s = x;
                _t = v.f;
                idx.push_back(v.s);
            }
        }
        else find_ep(v.f, x);
    }
}

void find_cyc(int x, int p){
    if(x == _t)oncyc[x]=1;
    else{
        for(auto v: graph[x]){
            if(v.f == p || (x == _s && v.f == _t) || (x == _t && v.f == _s))continue;
            find_cyc(v.f, x);
            if(oncyc[v.f]){
                idx.push_back(v.s);
                oncyc[x]=1;
            }
        }
    }
    if(oncyc[x])vert.push_back(x);
}

void solve(int x, int p){
    for(auto v: graph[x]){
        if(v.f == p || oncyc[v.f])continue;
        solve(v.f, p);
        ans[v.s]=val[v.f];
        val[x]-=val[v.f];
    }
}

void dfs(int x, int p){
    //cout << x << endl;
    for(auto v: graph[x]){
        if(v.f == p)continue;
        dfs(v.f, x);
        ans[v.s]=val[v.f];
        val[x]-=val[v.f];
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++)cin >> val[i];
    for(int i = 1; i <= m; i++){
        int a, b;
        cin >> a >> b;
        graph[a].push_back({b, i});
        graph[b].push_back({a, i});
    }
    if(m > n){
        cout << 0;
        return 0;
    }
    if(m == n){
        find_ep(1, 0);
        find_cyc(_s, 0);
        if(!(vert.size()&1)){
            cout << 0;
            return 0;
        }
        ll sum = 0;
        for(auto v: vert){
            solve(v, 0);
            sum += val[v];
        }
        sum/=2;
        for(int i = 1; i < vert.size(); i+=2)sum-=val[vert[i]];
        ans[idx[0]] = sum;
        for(int i = 1; i < idx.size(); i++)ans[idx[i]] = val[vert[i-1]]-ans[idx[i-1]];
    }
    else{
        dfs(1, 0);
    }
    for(int i = 1; i <= m; i++)cout << ans[i]*2 << "\n";

}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:101:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         for(int i = 1; i < vert.size(); i+=2)sum-=val[vert[i]];
      |                        ~~^~~~~~~~~~~~~
pipes.cpp:103:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |         for(int i = 1; i < idx.size(); i++)ans[idx[i]] = val[vert[i-1]]-ans[idx[i-1]];
      |                        ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2680 KB Output is correct
3 Correct 2 ms 2692 KB Output is correct
4 Correct 55 ms 9888 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2676 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 2 ms 2684 KB Output is correct
12 Correct 2 ms 2772 KB Output is correct
13 Correct 39 ms 8404 KB Output is correct
14 Correct 50 ms 9488 KB Output is correct
15 Correct 57 ms 9932 KB Output is correct
16 Correct 42 ms 8784 KB Output is correct
17 Correct 51 ms 9944 KB Output is correct
18 Correct 53 ms 9952 KB Output is correct
19 Correct 55 ms 13260 KB Output is correct
20 Correct 2 ms 2680 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 65 ms 9932 KB Output is correct
23 Correct 46 ms 8472 KB Output is correct
24 Correct 50 ms 9980 KB Output is correct
25 Correct 41 ms 8656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 61 ms 131072 KB Execution killed with signal 9
2 Runtime error 63 ms 131072 KB Execution killed with signal 9
3 Correct 78 ms 12876 KB Output is correct
4 Correct 39 ms 8264 KB Output is correct
5 Correct 34 ms 8420 KB Output is correct
6 Correct 154 ms 23408 KB Output is correct
7 Runtime error 64 ms 131072 KB Execution killed with signal 9
8 Correct 2 ms 2632 KB Output is correct
9 Correct 2 ms 2680 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Runtime error 62 ms 131072 KB Execution killed with signal 9
15 Runtime error 65 ms 131072 KB Execution killed with signal 9
16 Runtime error 64 ms 131072 KB Execution killed with signal 9
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2692 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2772 KB Output is correct
22 Runtime error 59 ms 131072 KB Execution killed with signal 9
23 Runtime error 99 ms 131072 KB Execution killed with signal 9
24 Runtime error 108 ms 131072 KB Execution killed with signal 9
25 Correct 79 ms 12896 KB Output is correct
26 Correct 43 ms 8232 KB Output is correct
27 Correct 34 ms 8060 KB Output is correct
28 Correct 36 ms 8624 KB Output is correct
29 Correct 128 ms 19660 KB Output is correct
30 Runtime error 106 ms 131072 KB Execution killed with signal 9
31 Runtime error 132 ms 131072 KB Execution killed with signal 9
32 Runtime error 108 ms 131072 KB Execution killed with signal 9
33 Correct 53 ms 14140 KB Output is correct
34 Correct 37 ms 8268 KB Output is correct
35 Correct 35 ms 8244 KB Output is correct
36 Correct 39 ms 8460 KB Output is correct
37 Correct 182 ms 23544 KB Output is correct
38 Runtime error 107 ms 131072 KB Execution killed with signal 9
39 Runtime error 103 ms 131072 KB Execution killed with signal 9
40 Runtime error 102 ms 131072 KB Execution killed with signal 9
41 Correct 62 ms 16800 KB Output is correct
42 Correct 52 ms 8052 KB Output is correct
43 Correct 35 ms 8088 KB Output is correct
44 Correct 35 ms 8444 KB Output is correct
45 Correct 119 ms 20668 KB Output is correct
46 Runtime error 117 ms 131072 KB Execution killed with signal 9
47 Runtime error 112 ms 131072 KB Execution killed with signal 9
48 Runtime error 107 ms 131072 KB Execution killed with signal 9
49 Correct 48 ms 10348 KB Output is correct
50 Correct 44 ms 8292 KB Output is correct
51 Correct 34 ms 8376 KB Output is correct
52 Correct 47 ms 8180 KB Output is correct
53 Correct 161 ms 20760 KB Output is correct
54 Runtime error 104 ms 131072 KB Execution killed with signal 9