답안 #1077719

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077719 2024-08-27T08:42:15 Z TVSown Pipes (BOI13_pipes) C++17
컴파일 오류
0 ms 0 KB
///*** Sown_Vipro ***///
/// ->TUYEN QUOC GIA<- ///

#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
#define F first
#define S second
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define all(a) a.begin(), a.end()
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define REP(i, a, b) for(int i = a; i >= b; --i)
#define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
#define out(name) if(fopen(name, "w")) freopen(name, "w", stdout);
#define szz(s) int(s.size())
#define int long long
const int N = 1e6 + 5, MAX = 1e6, oo = 1e9 + 5, MOD = 1e9 + 7;
int n, m;
int ans[N], c[N], deg[N];
vector<pi> e[N];

namespace sub1{
    void dfs(int u, int p){
        for(auto [v, i] : e[u]){
            if(v == p) continue;
            dfs(v, u);
            ans[i] = 2 * c[v];
            c[u] -= c[v];
        }
    }

    void solve(){
        dfs(1, 0);
        FOR(i, 1, m) cout << ans[i] << "\n";
    }
}

namespace sub2{
    int vst[N], root, A, B;
    vector<int> st;
    queue<int> q;
    void dfs(int u, int p, int type){
        st.pb(u);
//        cout << u << "\n";
        vst[u] = 1;
        if(type) A += c[u];
        else B += c[u];
        for(auto [v, i] : e[u]){
            if(vst[v]) continue;
            dfs(v, u, type ^ 1);
        }
    }

    void solve(){
        FOR(u, 1, n){
            if(deg[u] == 1) q.push(u);
        }
        while(szz(q)){
            int u = q.front(); q.pop();
            vst[u] = 1;
            for(auto [v, i] : e[u]){
                if(vst[v]) continue;
                ans[i] += 2 * c[u];
                c[u] -= c[u];
                c[v] -= c[u];
                --deg[v];
                if(deg[v] == 1){
                    q.push(v);
                }
            }
        }
        int cnt = 0;
        FOR(u, 1, n){
//            cout << c[u] << "\n";
            if(!vst[u]){
//                cout << u << "\n";
                ++cnt; root = u;
            }
        }
        if(cnt % 2 == 0){
            cout << 0; return;
        }
        dfs(root, 0, 1);
        st.pb(root);
        FOR(i, 0, szz(st) - 2){
            int u = st[i];
            for(auto [v, i] : e[u]){
                if(v == st[i + 1]){
                    if(i % 2) ans[i] = B - A;
                    else ans[i] = A - B;
                }
            }
        }

        FOR(i, 1, n) cout << ans[i] << "\n";
    }
}

void solve(){
    cin >> n >> m;
    FOR(u, 1, n) cin >> c[u];
    FOR(i, 1, m){
        int u, v; cin >> u >> v;
        e[u].pb({v, i});
        e[v].pb({u, i});
        ++deg[u];
        ++deg[v];
    }
    if(m == n - 1) sub1::solve();
    else if(m > n) cout << 0;
    else sub2::solve();
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    inp("in.txt");
    int t = 1;
//    cin >> t;
    while(t--){
        solve();
    }
}

Compilation message

pipes.cpp: In function 'void sub2::solve()':
pipes.cpp:20:13: error: expected primary-expression before 'long'
   20 | #define int long long
      |             ^~~~
pipes.cpp:19:16: note: in expansion of macro 'int'
   19 | #define szz(s) int(s.size())
      |                ^~~
pipes.cpp:62:15: note: in expansion of macro 'szz'
   62 |         while(szz(q)){
      |               ^~~
pipes.cpp:62:15: error: expected ')' before 'long'
   62 |         while(szz(q)){
      |              ~^
      |               )
pipes.cpp:20:13: error: expected primary-expression before 'long'
   20 | #define int long long
      |             ^~~~
pipes.cpp:19:16: note: in expansion of macro 'int'
   19 | #define szz(s) int(s.size())
      |                ^~~
pipes.cpp:62:15: note: in expansion of macro 'szz'
   62 |         while(szz(q)){
      |               ^~~
pipes.cpp:20:13: error: expected primary-expression before 'long'
   20 | #define int long long
      |             ^~~~
pipes.cpp:15:42: note: in definition of macro 'FOR'
   15 | #define FOR(i, a, b) for(int i = a; i <= b; ++i)
      |                                          ^
pipes.cpp:19:16: note: in expansion of macro 'int'
   19 | #define szz(s) int(s.size())
      |                ^~~
pipes.cpp:89:19: note: in expansion of macro 'szz'
   89 |         FOR(i, 0, szz(st) - 2){
      |                   ^~~
pipes.cpp:20:13: error: expected ';' before 'long'
   20 | #define int long long
      |             ^~~~
pipes.cpp:15:42: note: in definition of macro 'FOR'
   15 | #define FOR(i, a, b) for(int i = a; i <= b; ++i)
      |                                          ^
pipes.cpp:19:16: note: in expansion of macro 'int'
   19 | #define szz(s) int(s.size())
      |                ^~~
pipes.cpp:89:19: note: in expansion of macro 'szz'
   89 |         FOR(i, 0, szz(st) - 2){
      |                   ^~~
pipes.cpp:20:13: error: expected primary-expression before 'long'
   20 | #define int long long
      |             ^~~~
pipes.cpp:15:42: note: in definition of macro 'FOR'
   15 | #define FOR(i, a, b) for(int i = a; i <= b; ++i)
      |                                          ^
pipes.cpp:19:16: note: in expansion of macro 'int'
   19 | #define szz(s) int(s.size())
      |                ^~~
pipes.cpp:89:19: note: in expansion of macro 'szz'
   89 |         FOR(i, 0, szz(st) - 2){
      |                   ^~~
pipes.cpp:20:13: error: expected ')' before 'long'
   20 | #define int long long
      |             ^~~~
pipes.cpp:15:42: note: in definition of macro 'FOR'
   15 | #define FOR(i, a, b) for(int i = a; i <= b; ++i)
      |                                          ^
pipes.cpp:19:16: note: in expansion of macro 'int'
   19 | #define szz(s) int(s.size())
      |                ^~~
pipes.cpp:89:19: note: in expansion of macro 'szz'
   89 |         FOR(i, 0, szz(st) - 2){
      |                   ^~~
pipes.cpp:15:25: note: to match this '('
   15 | #define FOR(i, a, b) for(int i = a; i <= b; ++i)
      |                         ^
pipes.cpp:89:9: note: in expansion of macro 'FOR'
   89 |         FOR(i, 0, szz(st) - 2){
      |         ^~~
pipes.cpp:20:13: error: expected primary-expression before 'long'
   20 | #define int long long
      |             ^~~~
pipes.cpp:15:42: note: in definition of macro 'FOR'
   15 | #define FOR(i, a, b) for(int i = a; i <= b; ++i)
      |                                          ^
pipes.cpp:19:16: note: in expansion of macro 'int'
   19 | #define szz(s) int(s.size())
      |                ^~~
pipes.cpp:89:19: note: in expansion of macro 'szz'
   89 |         FOR(i, 0, szz(st) - 2){
      |                   ^~~
pipes.cpp:89:13: error: 'i' was not declared in this scope
   89 |         FOR(i, 0, szz(st) - 2){
      |             ^
pipes.cpp:15:47: note: in definition of macro 'FOR'
   15 | #define FOR(i, a, b) for(int i = a; i <= b; ++i)
      |                                               ^
pipes.cpp: In function 'int main()':
pipes.cpp:17:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~
pipes.cpp:121:5: note: in expansion of macro 'inp'
  121 |     inp("in.txt");
      |     ^~~