답안 #31319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
31319 2017-08-18T00:15:13 Z imaxblue Pipes (BOI13_pipes) C++14
100 / 100
383 ms 21352 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(zqfmgb, x) for (int zqfmgb=0; zqfmgb<x; ++zqfmgb)
#define fox1(zqfmgb, x) for (int zqfmgb=1; zqfmgb<=x; ++zqfmgb)
#define foxr(zqfmgb, x) for (int zqfmgb=x-1; zqfmgb>=0; --zqfmgb)
#define fox1r(zqfmgb, x) for (int zqfmgb=x; zqfmgb>0; --zqfmgb)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)

int n, m, a, b, N, C;
int c[100005], f[500005], k;
int in[100005], u[100005];
vector<pii> v[100005], s;
queue<int> q;
bool F;
void dfs(int N, int P){
    //cout << N << ' ' << C << endl;
    if (u[N]){
        //cout << "*" << endl;
        if (u[N]==C || F){
            cout << 0 << endl;
            exit(0);
        }
        F=1;
        s.pb(mp(N, -1));
        fox(l, s.size()-1){
            c[s[l+1].x]-=c[s[l].x];
            f[s[l].y]+=c[s[l].x];
            c[s[l].x]=0;
            //cout << s[l].x << ' ' << s[l].y << ' ' << f[s[l].y] << endl;
        }
        k=c[s[0].x]/2;
        fox(l, s.size()-1){
            f[s[l].y]+=k;
            k*=-1;
        }
        s.pop_back();
        return;
    }

    u[N]=C;
    fox(l, v[N].size()){
        if (in[v[N][l].x]==0 || v[N][l].x==P) continue;
        if (P==-1 && u[v[N][l].x]) continue;
        C=3-C;
        s.pb(mp(N, v[N][l].y));
        dfs(v[N][l].x, N);
        s.pop_back();
        C=3-C;
    }
}
int main(){
    scanf("%i%i", &n, &m);
    fox1(l, n) scanf("%i", &c[l]);
    fox(l, m){
        scanf("%i%i", &a, &b);
        v[a].pb(mp(b, l));
        v[b].pb(mp(a, l));
        in[a]++; in[b]++;
    }
    fox1(l, n){
        if (in[l]==1) q.push(l);
    }
    while(!q.empty()){
        N=q.front(); q.pop();
        if (in[N]!=1) continue;
        in[N]--;
        fox(l, v[N].size()){
            if (in[v[N][l].x]==0) continue;
            c[v[N][l].x]-=c[N];
            f[v[N][l].y]=c[N];
            //cout << N << ' ' << v[N][l].y << ' ' << c[N] << endl;
            in[v[N][l].x]--;
            if (in[v[N][l].x]==1) q.push(v[N][l].x);
        }
    }
    fox1(l, n){
        if (in[l]==0 || u[l]) continue;
        C=1; F=0;
        dfs(l, -1);
    }
    for (int l=0; l<m; ++l){
        f[l]*=2;
        printf("%i\n", f[l]);
    }
    return 0;
}

Compilation message

pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:18:49: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fox(zqfmgb, x) for (int zqfmgb=0; zqfmgb<x; ++zqfmgb)
                                                 ^
pipes.cpp:42:9: note: in expansion of macro 'fox'
         fox(l, s.size()-1){
         ^
pipes.cpp:18:49: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fox(zqfmgb, x) for (int zqfmgb=0; zqfmgb<x; ++zqfmgb)
                                                 ^
pipes.cpp:49:9: note: in expansion of macro 'fox'
         fox(l, s.size()-1){
         ^
pipes.cpp:18:49: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fox(zqfmgb, x) for (int zqfmgb=0; zqfmgb<x; ++zqfmgb)
                                                 ^
pipes.cpp:58:5: note: in expansion of macro 'fox'
     fox(l, v[N].size()){
     ^
pipes.cpp: In function 'int main()':
pipes.cpp:18:49: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fox(zqfmgb, x) for (int zqfmgb=0; zqfmgb<x; ++zqfmgb)
                                                 ^
pipes.cpp:84:9: note: in expansion of macro 'fox'
         fox(l, v[N].size()){
         ^
pipes.cpp:69:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i", &n, &m);
                          ^
pipes.cpp:70:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fox1(l, n) scanf("%i", &c[l]);
                                  ^
pipes.cpp:72:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i%i", &a, &b);
                              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7492 KB Output is correct
2 Correct 0 ms 7492 KB Output is correct
3 Correct 0 ms 7492 KB Output is correct
4 Correct 93 ms 11452 KB Output is correct
5 Correct 0 ms 7492 KB Output is correct
6 Correct 0 ms 7492 KB Output is correct
7 Correct 0 ms 7492 KB Output is correct
8 Correct 0 ms 7492 KB Output is correct
9 Correct 0 ms 7492 KB Output is correct
10 Correct 0 ms 7492 KB Output is correct
11 Correct 0 ms 7492 KB Output is correct
12 Correct 0 ms 7492 KB Output is correct
13 Correct 73 ms 10660 KB Output is correct
14 Correct 119 ms 11188 KB Output is correct
15 Correct 103 ms 11452 KB Output is correct
16 Correct 93 ms 10792 KB Output is correct
17 Correct 116 ms 11452 KB Output is correct
18 Correct 99 ms 11452 KB Output is correct
19 Correct 116 ms 10660 KB Output is correct
20 Correct 0 ms 7492 KB Output is correct
21 Correct 3 ms 7492 KB Output is correct
22 Correct 103 ms 11452 KB Output is correct
23 Correct 76 ms 10660 KB Output is correct
24 Correct 113 ms 11452 KB Output is correct
25 Correct 96 ms 10796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7492 KB Output is correct
2 Correct 3 ms 7492 KB Output is correct
3 Correct 106 ms 15528 KB Output is correct
4 Correct 116 ms 18844 KB Output is correct
5 Correct 96 ms 11188 KB Output is correct
6 Correct 383 ms 21352 KB Output is correct
7 Correct 0 ms 7492 KB Output is correct
8 Correct 0 ms 7492 KB Output is correct
9 Correct 0 ms 7492 KB Output is correct
10 Correct 0 ms 7492 KB Output is correct
11 Correct 0 ms 7492 KB Output is correct
12 Correct 0 ms 7492 KB Output is correct
13 Correct 0 ms 7492 KB Output is correct
14 Correct 0 ms 7492 KB Output is correct
15 Correct 0 ms 7492 KB Output is correct
16 Correct 0 ms 7492 KB Output is correct
17 Correct 0 ms 7492 KB Output is correct
18 Correct 0 ms 7492 KB Output is correct
19 Correct 0 ms 7492 KB Output is correct
20 Correct 3 ms 7492 KB Output is correct
21 Correct 0 ms 7624 KB Output is correct
22 Correct 3 ms 7492 KB Output is correct
23 Correct 113 ms 15612 KB Output is correct
24 Correct 123 ms 16364 KB Output is correct
25 Correct 113 ms 15528 KB Output is correct
26 Correct 126 ms 16788 KB Output is correct
27 Correct 103 ms 18520 KB Output is correct
28 Correct 93 ms 11324 KB Output is correct
29 Correct 289 ms 18712 KB Output is correct
30 Correct 116 ms 15296 KB Output is correct
31 Correct 126 ms 19852 KB Output is correct
32 Correct 116 ms 13120 KB Output is correct
33 Correct 126 ms 16572 KB Output is correct
34 Correct 133 ms 16616 KB Output is correct
35 Correct 99 ms 18844 KB Output is correct
36 Correct 69 ms 11188 KB Output is correct
37 Correct 346 ms 21352 KB Output is correct
38 Correct 116 ms 15588 KB Output is correct
39 Correct 99 ms 12320 KB Output is correct
40 Correct 123 ms 15936 KB Output is correct
41 Correct 99 ms 19852 KB Output is correct
42 Correct 106 ms 17020 KB Output is correct
43 Correct 116 ms 19324 KB Output is correct
44 Correct 83 ms 11188 KB Output is correct
45 Correct 276 ms 19768 KB Output is correct
46 Correct 113 ms 14916 KB Output is correct
47 Correct 103 ms 16068 KB Output is correct
48 Correct 126 ms 19592 KB Output is correct
49 Correct 99 ms 12492 KB Output is correct
50 Correct 93 ms 16676 KB Output is correct
51 Correct 106 ms 15368 KB Output is correct
52 Correct 119 ms 12076 KB Output is correct
53 Correct 253 ms 19504 KB Output is correct
54 Correct 116 ms 14720 KB Output is correct