Submission #1077624

#TimeUsernameProblemLanguageResultExecution timeMemory
1077624huyngodzzPipes (BOI13_pipes)C++14
74.07 / 100
123 ms23636 KiB
    ///huynhocute123///
#include<bits/stdc++.h>
using namespace std;
#define S second
#define F first
#define pii pair<int,int>
#define piii pair<int,pair<int,int>>
#define pb push_back
#define pi M_PI
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define REP(i, a, b) for(int i = b; i >= a; --i)
#define ALL(v) v.begin(),v.end()
#define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
#define out(name) if(fopen(name, "w")) freopen(name, "w", stdout);
//random_device rd;
//mt19937 rng(rd());
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
//#define int long long
const int maxN = 1e5 + 9 ;
const int  modd = 1e9 + 7;
const int base = 2309;
const int MAX = 1e9+9;
void minimize(int &u, int v){
    if(v < u) u = v;
}
void maximize(int &u, int v){
    if(v > u) u = v;
}
int n, k, t, m, res, a[maxN], ans[maxN], deg[maxN];
int l, r;
bool vis[maxN];
vector<pii> e[maxN];
namespace sub1{
    void dfs(int u ,int p){
        for(auto [x, id] : e[u]){
            if(x == p)continue;
            dfs(x , u);
            ans[id]= a[x];
            a[u] -= a[x];


        }
    }
    void solve(){
        dfs(1, 0);
        FOR(i, 1, m)cout << ans[i] *2 <<'\n';
    }
}
namespace sub2{
    queue<int> q;
    void solve(){
        FOR(i, 1, n){
            if(deg[i] == 1){
                q.push(i);
                    vis[i] =1;
//                    cout << i << " ";
            }
        }
//        cout <<endl;
        while(!q.empty()){
            int u = q.front();
//            cout << u << " ";
            q.pop();
            vis[u] =1;
            for(auto [x, id ] : e[u]){
                if(vis[x])continue;
                ans[id] = a[u];
//                cout << id << " " << a[u] <<'\n';
                a[x]-=a[u];
//                vis[x] = 1;
                deg[x]--;
                if(deg[x] == 1)q.push(x);

            }


        }
        int cnt =0;
        FOR(i, 1, n){
            if(!vis[i]){
                q.push(i);
                cnt++;
            }
        }
        if(cnt %2 ==0){
            cout << 0;
            return;
        }


    FOR(i, 1, m)cout << ans[i] *2 <<'\n';

    }
}
void solve(){
    cin >> n >> m;
    FOR(i, 1, n)cin >> a[i];
    FOR(i, 1, m){
        cin >> l >> r;
        e[l].pb({r, i});
        e[r].pb({l, i});
        deg[l]++;
        deg[r]++;
    }
    if(m > n ){
        cout << 0;
        return;
    }
    if(m == n)sub2::solve();
    else sub1::solve();

}
signed main(){
//    freopen("name.inp","r",stdin);
//    freopen("name.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    inp("task.inp");
    t = 1;
   // cin >> t;
    while( t-- )solve();

}

Compilation message (stderr)

pipes.cpp: In function 'void sub1::dfs(int, int)':
pipes.cpp:37:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |         for(auto [x, id] : e[u]){
      |                  ^
pipes.cpp: In function 'void sub2::solve()':
pipes.cpp:67:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   67 |             for(auto [x, id ] : e[u]){
      |                      ^
pipes.cpp: In function 'int main()':
pipes.cpp:13:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~
pipes.cpp:120:5: note: in expansion of macro 'inp'
  120 |     inp("task.inp");
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...