Submission #221958

# Submission time Handle Problem Language Result Execution time Memory
221958 2020-04-11T15:29:06 Z infinite_iq Pipes (BOI13_pipes) C++14
74.0741 / 100
843 ms 91240 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);
ll n , m , all ;
set<pll>v[500009];
ll val[500009] , ans[500009] , ret[500009] , VAL[500009] ,done[500009];;
ll start , sum , xxx ;
void dfs ( int node , int p ) {
        done [node] = 1;
        for ( auto u : v[node] ) {
                if ( u.fi == p ) C ;
                ll XXX = xxx ;
                if ( node != start ) XXX = -VAL[node];
                VAL[node] += XXX;
                VAL[u.fi] += XXX ;
                sum += XXX ;
                ret [ u.se ] = XXX ;
                if ( done[u.fi] ) C ;
                dfs ( u.fi , node ) ;
                break;
        }
}
int main () {
        mem ( ret , -1 ) ;
        cin >> n >> m ;
        for ( int i = 0 ; i < n ; i ++ ) cin >> val[i] ;
        for ( int i = 0 ; i < m ; i ++ ) {
                int a , b ;
                cin >> a >> b ;
                a -- , b -- ;
                v[a].ins( { b , i } ) ;
                v[b].ins( { a , i } ) ;
        }
        if ( m > n ) {
                cout << 0 << endl ;
                exit ( 0 ) ;
        }
        set<pll>s;
        for ( int i = 0 ; i < n ; i ++ ) {
                s.ins ( { v[i].size() , i } ) ;
        }
        while ( ( s.size() && s.begin()->fi==1 ) ) {
                int node = s.begin() -> se ;
                int to = v[node].begin() -> fi ;
                int id = v[node].begin() -> se ;
                s.era(s.begin());
                v[node].era( v[node].begin() );
                s.era ( { v[to].size() , to } ) ;
                v[to].era( { node , id } ) ;
                if ( v[to].size() ) s.ins ( { v[to].size() , to } ) ;
                ans [ id ] = - val [ node ] ;
                val [ to ] += ans [id] ;
                val [ node ] = 0 ;
        }
        if ( s.size() && s.size() % 2 == 0 ) cout << 0 << endl , exit ( 0 ) ;
        if ( !s.size() ) {
                for ( int i = 0 ; i < m ; i ++ ) {
                        cout << -ans [i] *2 << endl ;
                }
                exit ( 0 ) ;
        }
        for ( auto u : s ) VAL[u.se] = val[u.se] , all += val[u.se] ;
        all /= 2;
        start = s.begin()->se;
        xxx = 0 ;
        dfs(start,start);
        for ( auto u : s ) VAL[u.se] = val[u.se] ;
        xxx = all + sum ;
        xxx *= -1 ;
        mem(done,0);
        dfs(start,start);
        for ( int i = 0 ; i < m ;i ++ ) {
                if ( ret[i]!=-1 ) cout << ret[i]*2<<endl;
                else cout << -ans [i]*2 << endl;
        }
}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 27776 KB Output is correct
2 Correct 21 ms 27776 KB Output is correct
3 Correct 26 ms 27904 KB Output is correct
4 Correct 541 ms 48504 KB Output is correct
5 Correct 22 ms 27752 KB Output is correct
6 Correct 20 ms 27776 KB Output is correct
7 Correct 20 ms 27776 KB Output is correct
8 Correct 21 ms 27776 KB Output is correct
9 Correct 23 ms 27904 KB Output is correct
10 Correct 28 ms 27904 KB Output is correct
11 Correct 27 ms 27904 KB Output is correct
12 Correct 24 ms 27904 KB Output is correct
13 Correct 428 ms 44256 KB Output is correct
14 Correct 521 ms 47308 KB Output is correct
15 Correct 561 ms 48628 KB Output is correct
16 Correct 449 ms 45304 KB Output is correct
17 Correct 544 ms 48432 KB Output is correct
18 Correct 557 ms 48760 KB Output is correct
19 Correct 493 ms 48508 KB Output is correct
20 Correct 21 ms 27776 KB Output is correct
21 Correct 24 ms 27904 KB Output is correct
22 Correct 519 ms 48660 KB Output is correct
23 Correct 410 ms 44540 KB Output is correct
24 Correct 527 ms 48460 KB Output is correct
25 Correct 429 ms 45176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 31616 KB Output isn't correct
2 Incorrect 26 ms 31872 KB Output isn't correct
3 Correct 263 ms 46840 KB Output is correct
4 Correct 174 ms 41080 KB Output is correct
5 Correct 175 ms 40696 KB Output is correct
6 Correct 841 ms 91132 KB Output is correct
7 Incorrect 23 ms 31704 KB Output isn't correct
8 Incorrect 22 ms 31616 KB Output isn't correct
9 Correct 21 ms 27776 KB Output is correct
10 Correct 20 ms 27776 KB Output is correct
11 Correct 21 ms 27776 KB Output is correct
12 Correct 21 ms 27776 KB Output is correct
13 Correct 21 ms 27776 KB Output is correct
14 Incorrect 24 ms 31744 KB Output isn't correct
15 Incorrect 25 ms 31872 KB Output isn't correct
16 Incorrect 26 ms 31872 KB Output isn't correct
17 Correct 22 ms 27972 KB Output is correct
18 Correct 22 ms 27904 KB Output is correct
19 Correct 22 ms 27904 KB Output is correct
20 Correct 21 ms 27904 KB Output is correct
21 Correct 23 ms 28032 KB Output is correct
22 Incorrect 25 ms 31872 KB Output isn't correct
23 Incorrect 385 ms 49248 KB Output isn't correct
24 Incorrect 494 ms 53264 KB Output isn't correct
25 Correct 272 ms 46840 KB Output is correct
26 Correct 186 ms 41208 KB Output is correct
27 Correct 174 ms 40952 KB Output is correct
28 Correct 187 ms 41592 KB Output is correct
29 Correct 700 ms 78712 KB Output is correct
30 Incorrect 500 ms 52984 KB Output isn't correct
31 Incorrect 447 ms 53240 KB Output isn't correct
32 Incorrect 531 ms 53240 KB Output isn't correct
33 Correct 272 ms 48028 KB Output is correct
34 Correct 173 ms 41080 KB Output is correct
35 Correct 174 ms 40952 KB Output is correct
36 Correct 185 ms 41208 KB Output is correct
37 Correct 843 ms 91240 KB Output is correct
38 Incorrect 513 ms 53284 KB Output isn't correct
39 Incorrect 529 ms 53240 KB Output isn't correct
40 Incorrect 513 ms 53240 KB Output isn't correct
41 Correct 221 ms 48096 KB Output is correct
42 Correct 179 ms 41080 KB Output is correct
43 Correct 175 ms 41080 KB Output is correct
44 Correct 182 ms 40740 KB Output is correct
45 Correct 753 ms 83576 KB Output is correct
46 Incorrect 499 ms 53360 KB Output isn't correct
47 Incorrect 490 ms 53240 KB Output isn't correct
48 Incorrect 443 ms 53240 KB Output isn't correct
49 Correct 310 ms 46944 KB Output is correct
50 Correct 177 ms 40952 KB Output is correct
51 Correct 186 ms 41080 KB Output is correct
52 Correct 181 ms 40952 KB Output is correct
53 Correct 779 ms 84956 KB Output is correct
54 Incorrect 475 ms 52984 KB Output isn't correct