답안 #230462

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
230462 2020-05-10T07:35:48 Z mehrdad_sohrabi Pipes (BOI13_pipes) C++14
90.9259 / 100
608 ms 35300 KB
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
vector <int> g[N];
ll hi[N];
ll ans[N];
map <pii,int> mp;
ll val[N],par[N],vis[N];
ll ras1=0,ras2=0;
ll dfsd(ll v,ll p,ll h){
   // cout << v << " " << p << " " << h << endl;
    par[v]=p;
    hi[v]=h;
    for (auto u : g[v]){
        if (u==p) continue;
        if (hi[u]<hi[v] && hi[u]!=0){
            ras1=v,ras2=u;
        //    cout << v << " " << u << endl;
            continue;
        }
        if (hi[u]!=0) continue;
        dfsd(u,v,h+1);
    }
}
ll dfs(ll v,ll p){
    for (auto u : g[v]){
        if (u==p || vis[u]) continue;
        dfs(u,v);
        val[v]+=-val[u];
        mp[{u,v}]=2*-val[u];
        mp[{v,u}]=mp[{u,v}];
        val[u]=0;
    }
}
vector <pii> yal;
int32_t main(){
    ll n,m;
    cin >> n >> m;
    for (int i=1;i<=n;i++){
        cin >> val[i];
        val[i]=-val[i];
    }
    for (int i=0;i<m;i++){
        ll u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
        yal.pb({u,v});
    }
    if (m>n) kill(0);
    if (m==n-1){
        dfs(1,1);
        if (val[1]!=0) kill(0);
    }
    if (m==n){
        dfsd(1,1,1);
        vector <int> ras;

        while(ras1!=ras2){
            ras.pb(ras1);
            vis[ras1]=1;
            ras1=par[ras1];
        }
        ras.pb(ras2);
        vis[ras2]=1;
        for (int i=1;i<=n;i++){
            if (vis[i]){
                dfs(i,i);
            }
        }
        ll t=ras.size();
        for (int i=1;i<t;i++){
            ll v=ras[i],u=ras[(i+1)%t];
            val[u]+=-val[v];
            mp[{u,v}]=2*-val[v];
            mp[{v,u}]=2*-val[v];
            val[v]=0;

        }
        ll o=val[ras[0]];
        if (o%2!=0) kill(0);
        o/=2;
        o=-o;
        for (int i=0;i<t;i++){
            ll v=ras[i],u=ras[(i+1)%t];
            if (i%2==0){
                mp[{u,v}]+=2*o;
                mp[{v,u}]+=2*o;
            }
            else{
                mp[{u,v}]-=2*o;
                mp[{v,u}]-=2*o;
            }
        }
    }
    for (pii v : yal){
        cout << mp[v] << endl;
    }
}

Compilation message

pipes.cpp: In function 'll dfsd(ll, ll, ll)':
pipes.cpp:36:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
pipes.cpp: In function 'll dfs(ll, ll)':
pipes.cpp:46:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 8 ms 4992 KB Output is correct
3 Correct 9 ms 5248 KB Output is correct
4 Correct 301 ms 24036 KB Output is correct
5 Correct 7 ms 4992 KB Output is correct
6 Correct 7 ms 4992 KB Output is correct
7 Correct 7 ms 4992 KB Output is correct
8 Correct 7 ms 4992 KB Output is correct
9 Correct 9 ms 5248 KB Output is correct
10 Correct 9 ms 5248 KB Output is correct
11 Correct 9 ms 5248 KB Output is correct
12 Correct 10 ms 5376 KB Output is correct
13 Correct 222 ms 20300 KB Output is correct
14 Correct 281 ms 23268 KB Output is correct
15 Correct 313 ms 24292 KB Output is correct
16 Correct 251 ms 21476 KB Output is correct
17 Correct 296 ms 24096 KB Output is correct
18 Correct 308 ms 24308 KB Output is correct
19 Correct 300 ms 31332 KB Output is correct
20 Correct 7 ms 4992 KB Output is correct
21 Correct 9 ms 5248 KB Output is correct
22 Correct 309 ms 24164 KB Output is correct
23 Correct 230 ms 20196 KB Output is correct
24 Correct 331 ms 24292 KB Output is correct
25 Correct 251 ms 20964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 9 ms 5376 KB Output is correct
3 Incorrect 308 ms 27492 KB Output isn't correct
4 Correct 146 ms 10724 KB Output is correct
5 Correct 144 ms 10852 KB Output is correct
6 Correct 608 ms 27600 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Incorrect 7 ms 5120 KB Output isn't correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 8 ms 4992 KB Output is correct
12 Correct 8 ms 4992 KB Output is correct
13 Correct 7 ms 4992 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 9 ms 5376 KB Output is correct
16 Correct 9 ms 5248 KB Output is correct
17 Incorrect 9 ms 5248 KB Output isn't correct
18 Correct 9 ms 5120 KB Output is correct
19 Correct 8 ms 5120 KB Output is correct
20 Correct 9 ms 5120 KB Output is correct
21 Correct 10 ms 5248 KB Output is correct
22 Correct 10 ms 5376 KB Output is correct
23 Correct 275 ms 25060 KB Output is correct
24 Correct 342 ms 29156 KB Output is correct
25 Incorrect 335 ms 27492 KB Output isn't correct
26 Correct 141 ms 10724 KB Output is correct
27 Correct 143 ms 10596 KB Output is correct
28 Correct 150 ms 11236 KB Output is correct
29 Correct 469 ms 23600 KB Output is correct
30 Correct 319 ms 33516 KB Output is correct
31 Correct 356 ms 30820 KB Output is correct
32 Correct 312 ms 27364 KB Output is correct
33 Incorrect 336 ms 29284 KB Output isn't correct
34 Correct 140 ms 10724 KB Output is correct
35 Correct 140 ms 10724 KB Output is correct
36 Correct 148 ms 10980 KB Output is correct
37 Correct 575 ms 27728 KB Output is correct
38 Correct 354 ms 31332 KB Output is correct
39 Correct 333 ms 26852 KB Output is correct
40 Correct 324 ms 28900 KB Output is correct
41 Incorrect 340 ms 30820 KB Output isn't correct
42 Correct 144 ms 10596 KB Output is correct
43 Correct 144 ms 10596 KB Output is correct
44 Correct 162 ms 10856 KB Output is correct
45 Correct 466 ms 24656 KB Output is correct
46 Correct 335 ms 35300 KB Output is correct
47 Correct 392 ms 28900 KB Output is correct
48 Correct 388 ms 30564 KB Output is correct
49 Incorrect 304 ms 25956 KB Output isn't correct
50 Correct 147 ms 10852 KB Output is correct
51 Correct 141 ms 10980 KB Output is correct
52 Correct 142 ms 10628 KB Output is correct
53 Correct 507 ms 24784 KB Output is correct
54 Correct 323 ms 32744 KB Output is correct