Submission #222197

# Submission time Handle Problem Language Result Execution time Memory
222197 2020-04-12T10:17:17 Z infinite_iq Pipes (BOI13_pipes) C++14
90.9259 / 100
556 ms 21880 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 ;
                        }
                }
        }
}
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] *2 << endl ;
}
# Verdict Execution time Memory 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 341 ms 11864 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 7 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 2816 KB Output is correct
13 Correct 273 ms 9848 KB Output is correct
14 Correct 324 ms 11256 KB Output is correct
15 Correct 353 ms 11864 KB Output is correct
16 Correct 293 ms 10360 KB Output is correct
17 Correct 355 ms 11736 KB Output is correct
18 Correct 345 ms 11736 KB Output is correct
19 Correct 361 ms 11128 KB Output is correct
20 Correct 6 ms 2688 KB Output is correct
21 Correct 9 ms 2688 KB Output is correct
22 Correct 353 ms 11736 KB Output is correct
23 Correct 288 ms 9848 KB Output is correct
24 Correct 359 ms 11732 KB Output is correct
25 Correct 301 ms 10548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2688 KB Output is correct
2 Correct 9 ms 2816 KB Output is correct
3 Incorrect 343 ms 12280 KB Output isn't correct
4 Correct 145 ms 8312 KB Output is correct
5 Correct 160 ms 8440 KB Output is correct
6 Correct 556 ms 21880 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 7 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 2816 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 2816 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 292 ms 11384 KB Output is correct
24 Correct 383 ms 13048 KB Output is correct
25 Incorrect 349 ms 12540 KB Output isn't correct
26 Correct 139 ms 8312 KB Output is correct
27 Correct 147 ms 8184 KB Output is correct
28 Correct 145 ms 8696 KB Output is correct
29 Correct 451 ms 19652 KB Output is correct
30 Correct 371 ms 12280 KB Output is correct
31 Correct 376 ms 13816 KB Output is correct
32 Correct 356 ms 12128 KB Output is correct
33 Incorrect 351 ms 13048 KB Output isn't correct
34 Correct 139 ms 8312 KB Output is correct
35 Correct 135 ms 8312 KB Output is correct
36 Correct 144 ms 8576 KB Output is correct
37 Correct 548 ms 21880 KB Output is correct
38 Correct 360 ms 12616 KB Output is correct
39 Correct 349 ms 12024 KB Output is correct
40 Correct 366 ms 12956 KB Output is correct
41 Incorrect 374 ms 13816 KB Output isn't correct
42 Correct 150 ms 8428 KB Output is correct
43 Correct 143 ms 8184 KB Output is correct
44 Correct 139 ms 8440 KB Output is correct
45 Correct 455 ms 20088 KB Output is correct
46 Correct 369 ms 12280 KB Output is correct
47 Correct 364 ms 13048 KB Output is correct
48 Correct 382 ms 13816 KB Output is correct
49 Incorrect 333 ms 11748 KB Output isn't correct
50 Correct 142 ms 8312 KB Output is correct
51 Correct 154 ms 8444 KB Output is correct
52 Correct 138 ms 8184 KB Output is correct
53 Correct 497 ms 19804 KB Output is correct
54 Correct 355 ms 12280 KB Output is correct