답안 #1041844

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1041844 2024-08-02T08:41:19 Z KasymK 자매 도시 (APIO20_swap) C++17
37 / 100
2000 ms 12740 KB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int MOD = 1e9+7;
const int INF = 1e9;
const int MAXN = 2e5+5;
vector<pair<int, pii>> v;
int n, m, rep[MAXN], sz[MAXN], deg[MAXN], cnt[MAXN];

int find(int x){
    if(rep[x] == x)
        return x;
    return rep[x] = find(rep[x]); // path compression
}

bool check(int x, int y){
    return (find(x) == find(y));
}

void merge(int x, int y){
    if(check(x, y))
        return;
    x = find(x), y = find(y);
    if(sz[x] > sz[y])
        swap(x, y);
    sz[y] += sz[x];
    rep[x] = y;
}

void init(int N, int M, vector<int> U, vector<int> V, vector<int> W){
    n = N, m = M;
    for(int i = 0; i < m; ++i)
        v.pb({U[i], {V[i], W[i]}});
    auto cmp = [&](pair<int, pii>  a, pair<int, pii> b) -> bool {
        return (a.ss.ss < b.ss.ss);
    };
    sort(all(v), cmp);
}

int getMinimumFuelCapacity(int x, int y){
    int l = 2, r = m-1, ans = -1;
    while(l <= r){
        int mid = (l+r)/2;
        for(int i = 0; i < n; ++i)
            cnt[i] = 0, deg[i] = 0, rep[i] = i, sz[i] = 1;
        for(int i = 0; i <= mid; ++i){
            merge(v[i].ff, v[i].ss.ff);
            deg[v[i].ff]++, deg[v[i].ss.ff]++;
        }
        int ok = 0, mx = 0;
        for(int i = 0; i < n; ++i){
            if(!check(i, x))
                continue;
            cnt[deg[i]]++;
            umax(mx, deg[i]);
        }
        if(mx <= 2 and cnt[1] == 2)
            ok = 1;
        if(check(x, y) and !ok)
            ans = mid, r = mid-1;
        else
            l = mid+1;
    }
    int answer = 0;
    if(ans == -1)
        answer = -1;
    else
        answer = v[ans].ss.ss;
    return answer;
}

// int main(){
//     int AD;
//     scanf("%d", &AD);
//     init(5, 6, {0, 0, 1, 1, 1, 2}, {1, 2, 2, 3, 4, 3}, {4, 4, 1, 2, 10, 3});
//     while(AD--){
//         int x, y;
//         scanf("%d%d", &x, &y);
//         int answer = getMinimumFuelCapacity(x, y);
//         printf("%d\n", answer);
//     }
//     return 0;
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 78 ms 4920 KB Output is correct
10 Correct 175 ms 5220 KB Output is correct
11 Correct 221 ms 5480 KB Output is correct
12 Correct 220 ms 5436 KB Output is correct
13 Correct 170 ms 5428 KB Output is correct
14 Execution timed out 2077 ms 4924 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 2068 ms 7276 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2568 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2508 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2504 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 2 ms 2500 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 78 ms 4920 KB Output is correct
11 Correct 175 ms 5220 KB Output is correct
12 Correct 221 ms 5480 KB Output is correct
13 Correct 220 ms 5436 KB Output is correct
14 Correct 170 ms 5428 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 2 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2568 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2508 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2504 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 2 ms 2500 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 8 ms 3612 KB Output is correct
35 Correct 241 ms 7212 KB Output is correct
36 Correct 253 ms 7324 KB Output is correct
37 Correct 244 ms 7360 KB Output is correct
38 Correct 252 ms 7224 KB Output is correct
39 Correct 223 ms 7240 KB Output is correct
40 Correct 214 ms 6828 KB Output is correct
41 Correct 269 ms 7472 KB Output is correct
42 Correct 260 ms 7264 KB Output is correct
43 Correct 170 ms 7360 KB Output is correct
44 Correct 251 ms 7468 KB Output is correct
45 Correct 244 ms 10084 KB Output is correct
46 Correct 239 ms 7364 KB Output is correct
47 Correct 248 ms 7328 KB Output is correct
48 Correct 227 ms 7816 KB Output is correct
49 Correct 47 ms 10472 KB Output is correct
50 Correct 43 ms 7764 KB Output is correct
51 Correct 149 ms 8620 KB Output is correct
52 Correct 303 ms 12040 KB Output is correct
53 Correct 243 ms 11996 KB Output is correct
54 Correct 287 ms 12740 KB Output is correct
55 Correct 176 ms 7360 KB Output is correct
56 Correct 335 ms 12036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 78 ms 4920 KB Output is correct
10 Correct 175 ms 5220 KB Output is correct
11 Correct 221 ms 5480 KB Output is correct
12 Correct 220 ms 5436 KB Output is correct
13 Correct 170 ms 5428 KB Output is correct
14 Execution timed out 2077 ms 4924 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 78 ms 4920 KB Output is correct
11 Correct 175 ms 5220 KB Output is correct
12 Correct 221 ms 5480 KB Output is correct
13 Correct 220 ms 5436 KB Output is correct
14 Correct 170 ms 5428 KB Output is correct
15 Execution timed out 2077 ms 4924 KB Time limit exceeded
16 Halted 0 ms 0 KB -