답안 #222203

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
222203 2020-04-12T10:35:54 Z infinite_iq Pipes (BOI13_pipes) C++14
90.9259 / 100
545 ms 17272 KB
    #define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
    #include <bits/stdc++.h>
    using namespace std;
    #define sqr 340
    #define mid (l+r)/2
    #define pb push_back
    #define ppb pop_back
    #define fi first
    #define se second
    #define lb lower_bound
    #define ub upper_bound
    #define ins insert
    #define era erase
    #define C continue
    #define mem(dp,i) memset(dp,i,sizeof(dp))
    #define mset multiset
    typedef long long ll;
    typedef short int si;
    typedef long double ld;
    typedef pair<int,int> pi;
    typedef pair<ll,ll> pll;
    typedef vector<int> vi;
    typedef vector<ll> vll;
    typedef vector<pi> vpi;
    typedef vector<pll> vpll;
    const ll inf=1e18;
    const ld pai=acos(-1);
    int n , m , start ;
    vpi v[100009];
    ll a[100009] , deg[100009] , ans[100009] , done[100009];
    ll sum ( int node ) {
            done [ node ] = 1 ;
            ll ret = 0 ;
            for ( auto u : v[node] ) {
                    if ( done [u.fi] ) C ;
                    ret = sum ( u.fi ) ;
                    break ;
            }
            done [ node ] = 0 ;
            return ret + a[node] ;
    }
    ll go ( int node , ll p ) {
            done [ node ] = 1 ;
            ll ret = 0 ;
            for ( auto u : v[node] ) {
                    if ( done [u.fi] ) C ;
                    ret = go ( u.fi , a[ u.fi ] - p ) ;
                    break ;
            }
            done [ node ] = 0 ;
            return ret + p ;
    }
    void solve ( int node ) {
            done [node] = 1 ;
            ll out = 0 ;
            for ( auto u : v[node] ) {
                    if ( done [u.fi] ) C ;
                    a [ u.fi ] -= a[node] ;
                    ans [ u.se ] = a[node];
                    solve( u.fi ) ;
                    out = 1 ;
                    break;
            }
            if ( !out ) {
                    for ( auto u :v[node] ) {
                            if ( u.fi == start ) {
                                    ans [ u.se ] = a[ node ];
                                    break ;
                            }
                    }
            }
      		done [ node ] = 0 ;
    }
    int main () {
            cin >> n >> m ;
            for ( int i = 0 ; i < n ; i ++ ) cin >> a[i] ;
            for ( int i = 0 ; i < m ; i ++ ) {
                    int a , b ;
                    cin >> a >> b ;
                    a -- , b -- ;
                    v[a] .pb ( { b , i } ) ;
                    v[b] .pb ( { a , i } ) ;
            }
            if ( m > n ) cout << 0 << endl , exit ( 0 ) ;
            queue <int> q ;
            for ( int i = 0 ; i < n ; i ++ ) {
                    deg[i] = v[i].size() ;
                    if ( deg[i] == 1 ) q.push ( i ) ;
            }
            int N = n ;
            while ( q.size() ) {
                    N -- ;
                    int node = q.front () ;
                    q.pop () ;
                    done [ node ] = 1 ;
                    for ( auto U : v [node] ) {
                            int u = U.fi ;
                            int id= U.se ;
                            if ( done [u] ) C ;
                            ans [id] = a [node] ;
                            a [u] -= ans [id] ;
                            deg[u] -- ;
                            if ( deg [u] == 1 ) q.push ( u ) ;
                    }
            }
            if ( N && !N%2 ) cout << 0 << endl , exit ( 0 ) ;
            for ( int i = 0 ; i < n ; i ++ ) {
                    if ( done [i] ) C ;
                    start = i ;
                    ll all = sum ( i ) / 2 ;
                    ll ret = go ( i , 0 ) ;
                    a [ start ] = all - ret ; ;
                    solve ( i ) ;
                    break ;
            }
            for ( int i = 0 ; i < m ; i ++ ) cout << ans [i] *2ll << endl ;
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 9 ms 2816 KB Output is correct
4 Correct 334 ms 10072 KB Output is correct
5 Correct 6 ms 2688 KB Output is correct
6 Correct 6 ms 2688 KB Output is correct
7 Correct 6 ms 2688 KB Output is correct
8 Correct 6 ms 2688 KB Output is correct
9 Correct 9 ms 2688 KB Output is correct
10 Correct 9 ms 2816 KB Output is correct
11 Correct 9 ms 2816 KB Output is correct
12 Correct 9 ms 2688 KB Output is correct
13 Correct 277 ms 8696 KB Output is correct
14 Correct 314 ms 9848 KB Output is correct
15 Correct 348 ms 10208 KB Output is correct
16 Correct 287 ms 9208 KB Output is correct
17 Correct 350 ms 10072 KB Output is correct
18 Correct 365 ms 10200 KB Output is correct
19 Correct 353 ms 9464 KB Output is correct
20 Correct 6 ms 2688 KB Output is correct
21 Correct 8 ms 2688 KB Output is correct
22 Correct 348 ms 10196 KB Output is correct
23 Correct 265 ms 8696 KB Output is correct
24 Correct 356 ms 10324 KB Output is correct
25 Correct 295 ms 8952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 9 ms 2816 KB Output is correct
3 Incorrect 348 ms 10872 KB Output isn't correct
4 Correct 136 ms 6776 KB Output is correct
5 Correct 138 ms 6904 KB Output is correct
6 Correct 532 ms 17272 KB Output is correct
7 Correct 6 ms 2688 KB Output is correct
8 Correct 6 ms 2688 KB Output is correct
9 Incorrect 6 ms 2688 KB Output isn't correct
10 Correct 6 ms 2688 KB Output is correct
11 Correct 6 ms 2688 KB Output is correct
12 Correct 6 ms 2688 KB Output is correct
13 Correct 6 ms 2688 KB Output is correct
14 Correct 6 ms 2688 KB Output is correct
15 Correct 9 ms 2816 KB Output is correct
16 Correct 9 ms 2688 KB Output is correct
17 Incorrect 9 ms 2816 KB Output isn't correct
18 Correct 7 ms 2688 KB Output is correct
19 Correct 7 ms 2688 KB Output is correct
20 Correct 7 ms 2688 KB Output is correct
21 Correct 8 ms 2816 KB Output is correct
22 Correct 9 ms 2816 KB Output is correct
23 Correct 294 ms 10008 KB Output is correct
24 Correct 355 ms 11384 KB Output is correct
25 Incorrect 338 ms 11000 KB Output isn't correct
26 Correct 140 ms 6780 KB Output is correct
27 Correct 136 ms 6648 KB Output is correct
28 Correct 143 ms 7036 KB Output is correct
29 Correct 446 ms 14712 KB Output is correct
30 Correct 373 ms 10744 KB Output is correct
31 Correct 361 ms 12280 KB Output is correct
32 Correct 340 ms 10616 KB Output is correct
33 Incorrect 365 ms 11512 KB Output isn't correct
34 Correct 140 ms 6648 KB Output is correct
35 Correct 139 ms 6668 KB Output is correct
36 Correct 139 ms 7032 KB Output is correct
37 Correct 545 ms 17272 KB Output is correct
38 Correct 372 ms 11128 KB Output is correct
39 Correct 354 ms 10360 KB Output is correct
40 Correct 355 ms 11256 KB Output is correct
41 Incorrect 369 ms 12152 KB Output isn't correct
42 Correct 140 ms 6572 KB Output is correct
43 Correct 137 ms 6648 KB Output is correct
44 Correct 135 ms 6904 KB Output is correct
45 Correct 450 ms 15352 KB Output is correct
46 Correct 360 ms 10616 KB Output is correct
47 Correct 382 ms 11384 KB Output is correct
48 Correct 368 ms 12104 KB Output is correct
49 Incorrect 344 ms 10292 KB Output isn't correct
50 Correct 137 ms 6776 KB Output is correct
51 Correct 137 ms 6916 KB Output is correct
52 Correct 137 ms 6904 KB Output is correct
53 Correct 473 ms 15224 KB Output is correct
54 Correct 354 ms 10744 KB Output is correct