답안 #253840

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253840 2020-07-28T21:37:53 Z aZvezda Pipes (BOI13_pipes) C++14
65 / 100
392 ms 24444 KB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const ll MAX_N = 1e5 + 10;
set<pair<ll, ll> > g[MAX_N];
ll ans[MAX_N], arr[MAX_N];

struct cmp {
    bool operator ()(const ll &a, const ll &b) const {
        if(g[a].size() == g[b].size()) {
            return a < b;
        }
        return g[a].size() < g[b].size();
    }
};

multiset<ll, cmp> pq;

void removeBranches() {
    while(!pq.empty() && g[*(pq.begin())].size() == 1) {
        ll curr = *(pq.begin()); pq.erase(pq.begin());
        auto other = *(g[curr].begin());
        pq.erase(other.first);
        ans[other.second] = arr[curr];
        arr[other.first] -= arr[curr];
        g[other.first].erase({curr, other.second});
        pq.insert(other.first);
    }
}

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n, m;
    cin >> n >> m;
    if(m > n) {cout << 0 << endl; return 0;}
    for(ll i = 1; i <= n; i ++) {
        cin >> arr[i];
    }
    for(ll i = 0; i < m; i ++) {
        ll a, b;
        cin >> a >> b;
        g[a].insert({b, i});
        g[b].insert({a, i});
    }
    for(ll i = 1; i <= n; i ++) {
        pq.insert(i);
    }
    removeBranches();
    for(ll i = 0; i < m; i ++) {
        cout << ans[i] * 2 << endl;
    }
    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 5 ms 4992 KB Output is correct
3 Correct 5 ms 5248 KB Output is correct
4 Correct 349 ms 24312 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 3 ms 4992 KB Output is correct
8 Correct 4 ms 4992 KB Output is correct
9 Correct 5 ms 5248 KB Output is correct
10 Correct 6 ms 5248 KB Output is correct
11 Correct 5 ms 5248 KB Output is correct
12 Correct 5 ms 5248 KB Output is correct
13 Correct 235 ms 20472 KB Output is correct
14 Correct 283 ms 23288 KB Output is correct
15 Correct 305 ms 24440 KB Output is correct
16 Correct 251 ms 21752 KB Output is correct
17 Correct 359 ms 24336 KB Output is correct
18 Correct 392 ms 24444 KB Output is correct
19 Correct 285 ms 24440 KB Output is correct
20 Correct 3 ms 4992 KB Output is correct
21 Correct 6 ms 5248 KB Output is correct
22 Correct 309 ms 24440 KB Output is correct
23 Correct 249 ms 20596 KB Output is correct
24 Correct 324 ms 24440 KB Output is correct
25 Correct 274 ms 21240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 4992 KB Output isn't correct
2 Incorrect 5 ms 5248 KB Output isn't correct
3 Incorrect 259 ms 23160 KB Output isn't correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 5 ms 4992 KB Output is correct
7 Incorrect 3 ms 4992 KB Output isn't correct
8 Incorrect 4 ms 4992 KB Output isn't correct
9 Incorrect 3 ms 4992 KB Output isn't correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 4 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Incorrect 3 ms 4992 KB Output isn't correct
15 Incorrect 4 ms 5248 KB Output isn't correct
16 Incorrect 5 ms 5248 KB Output isn't correct
17 Incorrect 5 ms 5248 KB Output isn't correct
18 Correct 3 ms 4992 KB Output is correct
19 Correct 3 ms 4992 KB Output is correct
20 Correct 5 ms 4992 KB Output is correct
21 Correct 3 ms 4992 KB Output is correct
22 Incorrect 6 ms 5248 KB Output isn't correct
23 Incorrect 194 ms 20728 KB Output isn't correct
24 Incorrect 266 ms 24312 KB Output isn't correct
25 Incorrect 286 ms 23164 KB Output isn't correct
26 Correct 4 ms 4992 KB Output is correct
27 Correct 3 ms 4992 KB Output is correct
28 Correct 3 ms 4992 KB Output is correct
29 Correct 3 ms 4992 KB Output is correct
30 Incorrect 258 ms 23928 KB Output isn't correct
31 Incorrect 219 ms 24312 KB Output isn't correct
32 Incorrect 296 ms 24312 KB Output isn't correct
33 Incorrect 253 ms 24312 KB Output isn't correct
34 Correct 4 ms 5120 KB Output is correct
35 Correct 3 ms 4992 KB Output is correct
36 Correct 5 ms 4992 KB Output is correct
37 Correct 3 ms 4992 KB Output is correct
38 Incorrect 241 ms 24276 KB Output isn't correct
39 Incorrect 312 ms 24312 KB Output isn't correct
40 Incorrect 287 ms 24296 KB Output isn't correct
41 Incorrect 202 ms 24184 KB Output isn't correct
42 Correct 4 ms 4992 KB Output is correct
43 Correct 3 ms 4992 KB Output is correct
44 Correct 4 ms 4992 KB Output is correct
45 Correct 3 ms 4992 KB Output is correct
46 Incorrect 232 ms 24328 KB Output isn't correct
47 Incorrect 260 ms 24312 KB Output isn't correct
48 Incorrect 212 ms 24184 KB Output isn't correct
49 Incorrect 315 ms 23288 KB Output isn't correct
50 Correct 3 ms 4992 KB Output is correct
51 Correct 4 ms 4992 KB Output is correct
52 Correct 3 ms 4992 KB Output is correct
53 Correct 3 ms 4992 KB Output is correct
54 Incorrect 244 ms 24184 KB Output isn't correct