답안 #631403

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

#define f first
#define s second

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){
    assert(!vis[x]);
    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;
                break;
            }
        }
    }
    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;
    if(m > n){
        cout << 0;
        return 0;
    }
    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){
        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:102:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |         for(int i = 1; i < vert.size(); i+=2)sum-=val[vert[i]];
      |                        ~~^~~~~~~~~~~~~
pipes.cpp:104:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |         for(int i = 1; i < idx.size(); i++)ans[idx[i]] = val[vert[i-1]]-ans[idx[i-1]];
      |                        ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 57 ms 8360 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2744 KB Output is correct
12 Correct 3 ms 2772 KB Output is correct
13 Correct 37 ms 7148 KB Output is correct
14 Correct 50 ms 8012 KB Output is correct
15 Correct 60 ms 8368 KB Output is correct
16 Correct 61 ms 7480 KB Output is correct
17 Correct 48 ms 8344 KB Output is correct
18 Correct 51 ms 8300 KB Output is correct
19 Correct 54 ms 11692 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 62 ms 8320 KB Output is correct
23 Correct 35 ms 7116 KB Output is correct
24 Correct 49 ms 8304 KB Output is correct
25 Correct 38 ms 7420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 62 ms 131072 KB Execution killed with signal 9
2 Runtime error 68 ms 131072 KB Execution killed with signal 9
3 Correct 53 ms 11372 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Runtime error 60 ms 131072 KB Execution killed with signal 9
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Runtime error 63 ms 131072 KB Execution killed with signal 9
15 Runtime error 64 ms 131072 KB Execution killed with signal 9
16 Runtime error 64 ms 131072 KB Execution killed with signal 9
17 Correct 2 ms 2772 KB Output is correct
18 Correct 1 ms 2584 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Runtime error 62 ms 131072 KB Execution killed with signal 9
23 Runtime error 106 ms 131072 KB Execution killed with signal 9
24 Runtime error 117 ms 131072 KB Execution killed with signal 9
25 Correct 47 ms 11464 KB Output is correct
26 Correct 1 ms 2644 KB Output is correct
27 Correct 1 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Runtime error 106 ms 131072 KB Execution killed with signal 9
31 Runtime error 131 ms 131072 KB Execution killed with signal 9
32 Runtime error 113 ms 131072 KB Execution killed with signal 9
33 Correct 50 ms 12532 KB Output is correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 2 ms 2644 KB Output is correct
36 Correct 1 ms 2644 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Runtime error 109 ms 131072 KB Execution killed with signal 9
39 Runtime error 136 ms 131072 KB Execution killed with signal 9
40 Runtime error 109 ms 131072 KB Execution killed with signal 9
41 Correct 57 ms 15228 KB Output is correct
42 Correct 2 ms 2644 KB Output is correct
43 Correct 1 ms 2644 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 1 ms 2644 KB Output is correct
46 Runtime error 111 ms 131072 KB Execution killed with signal 9
47 Runtime error 102 ms 131072 KB Execution killed with signal 9
48 Runtime error 114 ms 131072 KB Execution killed with signal 9
49 Correct 44 ms 8916 KB Output is correct
50 Correct 1 ms 2644 KB Output is correct
51 Correct 2 ms 2644 KB Output is correct
52 Correct 2 ms 2644 KB Output is correct
53 Correct 2 ms 2644 KB Output is correct
54 Runtime error 104 ms 131072 KB Execution killed with signal 9