Submission #153716

# Submission time Handle Problem Language Result Execution time Memory
153716 2019-09-15T10:52:08 Z brcode Pipes (BOI13_pipes) C++14
65 / 100
766 ms 32364 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
const long long MAXN = 1e5+5;
long long p[MAXN];
long long dep[MAXN];
long long val[MAXN];
long long node[MAXN];
vector<long long> v1[MAXN];
bool visited[MAXN];
vector<long long> v2[MAXN];
long long maxdepth;
map<pair<long long,long long>,long long> m1;
vector<long long> process;
long long ans[MAXN];
void dfs(long long curr,long long par,long long depth){
    p[curr] = par;
    dep[curr] = depth;
    v2[depth].push_back(curr);
    maxdepth = max(maxdepth,depth);
    for(long long x:v1[curr]){
        if(x!=par){
            dfs(x,curr,depth+1);
        }
    }
    
}    long long n,m;
void solve(){
    bool ok = false;
    int x1,y1;
    for(int i=1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        
        v1[x].push_back(y);
        v1[y].push_back(x);
        if(!ok){
            ok = true;
            x1 = x;
            y1= y;
        }
    }
    int curr = 1;
    vector<long long> hold;
    hold.push_back(x1);
    hold.push_back(y1);
    visited[x1] = true;
    curr = y1;
    while(!visited[curr]){
       
        visited[curr] = true;
        hold.push_back(curr);
       
        for(int x:v1[curr]){
            if(!visited[x]){
                curr = x;
                
                break;
            }
        }
        if(visited[curr]){
            break;
        }
      
        
        
    }
      ans[0] = val[0];
    for(int i=0;i<n;i++){
            ans[0]+=val[0];
            if(i%2){
                ans[0]-=2*val[i];
            }
        }
        ans[0]/=2;
        for(int i=1;i<=n;i++){
            ans[i] = val[i-1]-ans[i-1];
        }
      
        for(int i=2;i<=n;i++){
            cout<<ans[i]*2<<endl;
            
        }
        cout<<ans[1]*2<<endl;
}
int main(){

    cin>>n>>m;
    if(m>n){
        cout<<0<<endl;
        return 0;
    }
    
    for(long long i=1;i<=n;i++){
        cin>>val[i];
    }
    if(n==m){
        solve();
        
        return 0;
    }
   
    for(long long i=1;i<n;i++){
        long long x,y;
        cin>>x>>y;
        v1[x].push_back(y);
        v1[y].push_back(x);
        m1[make_pair(x,y)] = i;
        
        m1[make_pair(y,x)] = i;
    }
    dfs(1,0,1);
    for(long long i=maxdepth;i>=1;i--){
        for(long long x:v2[i]){
            process.push_back(x);
        }
    }
    for(long long x:process){
        long long edgew = (val[x]-node[x])*2;
        node[p[x]]+=val[x]-node[x];
        ans[m1[make_pair(x,p[x])]] = edgew;
    }
    if(node[0]!=0){
        cout<<0<<endl;
        return 0;
    }
    for(long long i=1;i<n;i++){
        cout<<ans[i]<<endl;
    }
}

Compilation message

pipes.cpp: In function 'void solve()':
pipes.cpp:32:12: warning: 'y1' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int x1,y1;
            ^~
pipes.cpp:47:19: warning: 'x1' may be used uninitialized in this function [-Wmaybe-uninitialized]
     hold.push_back(x1);
     ~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5116 KB Output is correct
2 Correct 7 ms 5112 KB Output is correct
3 Correct 11 ms 5240 KB Output is correct
4 Correct 706 ms 29040 KB Output is correct
5 Correct 8 ms 5112 KB Output is correct
6 Correct 8 ms 5112 KB Output is correct
7 Correct 8 ms 5112 KB Output is correct
8 Correct 7 ms 5112 KB Output is correct
9 Correct 11 ms 5240 KB Output is correct
10 Correct 11 ms 5368 KB Output is correct
11 Correct 11 ms 5240 KB Output is correct
12 Correct 12 ms 5368 KB Output is correct
13 Correct 578 ms 24340 KB Output is correct
14 Correct 665 ms 28072 KB Output is correct
15 Correct 766 ms 29260 KB Output is correct
16 Correct 593 ms 25724 KB Output is correct
17 Correct 753 ms 29236 KB Output is correct
18 Correct 728 ms 29280 KB Output is correct
19 Correct 695 ms 32364 KB Output is correct
20 Correct 8 ms 5112 KB Output is correct
21 Correct 11 ms 5240 KB Output is correct
22 Correct 708 ms 29292 KB Output is correct
23 Correct 532 ms 24284 KB Output is correct
24 Correct 694 ms 29276 KB Output is correct
25 Correct 557 ms 25284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5112 KB Output isn't correct
2 Incorrect 15 ms 5112 KB Output isn't correct
3 Incorrect 420 ms 11988 KB Output isn't correct
4 Correct 6 ms 4984 KB Output is correct
5 Correct 6 ms 5088 KB Output is correct
6 Correct 6 ms 4984 KB Output is correct
7 Incorrect 7 ms 5156 KB Output isn't correct
8 Incorrect 6 ms 4984 KB Output isn't correct
9 Incorrect 7 ms 5112 KB Output isn't correct
10 Correct 7 ms 5112 KB Output is correct
11 Correct 6 ms 5032 KB Output is correct
12 Correct 6 ms 5112 KB Output is correct
13 Correct 7 ms 4984 KB Output is correct
14 Incorrect 7 ms 5112 KB Output isn't correct
15 Incorrect 11 ms 5112 KB Output isn't correct
16 Incorrect 10 ms 5084 KB Output isn't correct
17 Incorrect 10 ms 5084 KB Output isn't correct
18 Correct 6 ms 5084 KB Output is correct
19 Correct 6 ms 4984 KB Output is correct
20 Correct 6 ms 5088 KB Output is correct
21 Correct 6 ms 4984 KB Output is correct
22 Incorrect 11 ms 5112 KB Output isn't correct
23 Incorrect 370 ms 11276 KB Output isn't correct
24 Incorrect 446 ms 12820 KB Output isn't correct
25 Incorrect 415 ms 12024 KB Output isn't correct
26 Correct 6 ms 4984 KB Output is correct
27 Correct 6 ms 4984 KB Output is correct
28 Correct 6 ms 4984 KB Output is correct
29 Correct 6 ms 4984 KB Output is correct
30 Incorrect 443 ms 12428 KB Output isn't correct
31 Incorrect 445 ms 12280 KB Output isn't correct
32 Incorrect 473 ms 12544 KB Output isn't correct
33 Incorrect 448 ms 12408 KB Output isn't correct
34 Correct 6 ms 4988 KB Output is correct
35 Correct 6 ms 4984 KB Output is correct
36 Correct 6 ms 4984 KB Output is correct
37 Correct 6 ms 4984 KB Output is correct
38 Incorrect 447 ms 12504 KB Output isn't correct
39 Incorrect 440 ms 12536 KB Output isn't correct
40 Incorrect 443 ms 12292 KB Output isn't correct
41 Incorrect 461 ms 12120 KB Output isn't correct
42 Correct 8 ms 4984 KB Output is correct
43 Correct 6 ms 4984 KB Output is correct
44 Correct 7 ms 4984 KB Output is correct
45 Correct 6 ms 4984 KB Output is correct
46 Incorrect 443 ms 12212 KB Output isn't correct
47 Incorrect 446 ms 12312 KB Output isn't correct
48 Incorrect 457 ms 12288 KB Output isn't correct
49 Incorrect 414 ms 12280 KB Output isn't correct
50 Correct 6 ms 4984 KB Output is correct
51 Correct 7 ms 4984 KB Output is correct
52 Correct 6 ms 5112 KB Output is correct
53 Correct 6 ms 4984 KB Output is correct
54 Incorrect 438 ms 12536 KB Output isn't correct