답안 #502391

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502391 2022-01-05T21:08:44 Z Victor 자매 도시 (APIO20_swap) C++17
24 / 100
2000 ms 14040 KB
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include "swap.h"

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto &a : x)

#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout << #x << " = " << x << endl

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;

const int INF = 1'000'000'007;

struct ufds_rollback {
    vector<vii>p;
    vi rank,max_deg,possible,deg;
    vector<bool>cycle;
    
    ufds_rollback(int n) {
        deg.assign(n,0);
        rank.assign(n,0);
        cycle.assign(n,0);
        max_deg.assign(n,0);
        possible.assign(n,INF);

        p.resize(n);
        rep(i,0,n)p[i].emplace_back(0,i);
    }

    int find(int i,const int &mx) {
        auto it=upper_bound(all(p[i]),ii(mx,INF));
        --it;
        //cout<<"i = "<<i<<" mx = "<<mx<<" val = "<<it->first<<" p = "<<it->second<<endl;
        if(it->second==i)return i;
        else return find(it->second,mx);
        return 0;
    }

    void union_set(int i,int j,int val) {
        int u=find(i,val);
        int v=find(j,val);
        if(u==v) {
            cycle[u]=1;
            possible[u]=min(possible[u],val);
            return;
        }

        ++deg[i];
        ++deg[j];
        max_deg[u]=max(max_deg[u],deg[i]);
        max_deg[v]=max(max_deg[v],deg[j]);

        if(rank[u]<rank[v])swap(u,v);
        if(p[v].back().first==val)p[v].pop_back();
        p[v].emplace_back(val,u);
        max_deg[u]=max(max_deg[u],max_deg[v]);
        
        if(possible[v]!=INF||max_deg[u]>=3) possible[u]=min(possible[u],val);
    }
};

ufds_rollback ufds(100001);
vector<iii> edges;
int n,m;

void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
    n=N;
    m=M;
    rep(i,0,m) edges.pb({W[i],{U[i],V[i]}});
    sort(all(edges));
    //rep(i,0,n) {
    //    auto it=ufds.p[i].begin();
    //    cout<<sz(ufds.p[i])<<' '<<it->first<<' '<<it->second<<' ';
    //    ufds.find(i,0);
    //}
    trav(edge,edges) {
        int u,v,w;
        w=edge.first;
        tie(u,v)=edge.second;
        ufds.union_set(u,v,w);
        //cout<<"u = "<<u<<" v = "<<v<<" w = "<<w<<endl;
    }
    edges.pb({-1,{0,0}});
}

int getMinimumFuelCapacity(int X, int Y) {
    int u=X,v=Y;
    int lo=0,hi=m;
    while(lo!=hi) {
        int mid=(lo+hi)/2;
        int w=edges[mid].first;
        int p=ufds.find(u,w);
        if(p==ufds.find(v,w)&&ufds.possible[p]<=w) hi=mid;
        else lo=mid+1;
    }
    return edges[lo].first;
}

/*
int main() {
    int N, M;
    assert(2 == scanf("%d %d", &N, &M));

    std::vector<int> U(M), V(M), W(M);
    for (int i = 0; i < M; ++i) {
        assert(3 == scanf("%d %d %d", &U[i], &V[i], &W[i]));
    }

    int Q;
    assert(1 == scanf("%d", &Q));

    std::vector<int> X(Q), Y(Q);
    for (int i = 0; i < Q; ++i) {
        assert(2 == scanf("%d %d", &X[i], &Y[i]));
    }

    init(N, M, U, V, W);

    std::vector<int> minimum_fuel_capacities(Q);
    for (int i = 0; i < Q; ++i) {
        minimum_fuel_capacities[i] = getMinimumFuelCapacity(X[i], Y[i]);
    }

    for (int i = 0; i < Q; ++i) {
        printf("%d\n", minimum_fuel_capacities[i]);
    }

    return 0;
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7260 KB Output is correct
2 Correct 6 ms 7244 KB Output is correct
3 Correct 6 ms 7244 KB Output is correct
4 Correct 6 ms 7372 KB Output is correct
5 Correct 7 ms 7372 KB Output is correct
6 Correct 7 ms 7408 KB Output is correct
7 Correct 8 ms 7336 KB Output is correct
8 Correct 8 ms 7372 KB Output is correct
9 Correct 48 ms 10844 KB Output is correct
10 Correct 65 ms 11184 KB Output is correct
11 Correct 85 ms 11200 KB Output is correct
12 Correct 68 ms 11336 KB Output is correct
13 Correct 128 ms 11344 KB Output is correct
14 Correct 96 ms 10968 KB Output is correct
15 Correct 554 ms 12864 KB Output is correct
16 Correct 578 ms 12700 KB Output is correct
17 Correct 501 ms 12864 KB Output is correct
18 Execution timed out 2075 ms 12880 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7260 KB Output is correct
2 Correct 6 ms 7244 KB Output is correct
3 Correct 217 ms 13692 KB Output is correct
4 Correct 180 ms 13592 KB Output is correct
5 Correct 256 ms 14040 KB Output is correct
6 Correct 186 ms 13748 KB Output is correct
7 Correct 193 ms 13880 KB Output is correct
8 Correct 220 ms 13732 KB Output is correct
9 Correct 180 ms 13684 KB Output is correct
10 Correct 195 ms 13736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7260 KB Output is correct
2 Correct 6 ms 7244 KB Output is correct
3 Correct 6 ms 7244 KB Output is correct
4 Correct 6 ms 7372 KB Output is correct
5 Correct 7 ms 7372 KB Output is correct
6 Correct 7 ms 7408 KB Output is correct
7 Correct 8 ms 7336 KB Output is correct
8 Correct 8 ms 7372 KB Output is correct
9 Correct 6 ms 7244 KB Output is correct
10 Correct 6 ms 7372 KB Output is correct
11 Correct 10 ms 7380 KB Output is correct
12 Correct 7 ms 7372 KB Output is correct
13 Correct 7 ms 7372 KB Output is correct
14 Correct 7 ms 7372 KB Output is correct
15 Correct 6 ms 7372 KB Output is correct
16 Correct 7 ms 7372 KB Output is correct
17 Correct 6 ms 7356 KB Output is correct
18 Correct 6 ms 7372 KB Output is correct
19 Correct 6 ms 7372 KB Output is correct
20 Correct 6 ms 7372 KB Output is correct
21 Correct 6 ms 7372 KB Output is correct
22 Correct 8 ms 7372 KB Output is correct
23 Correct 6 ms 7324 KB Output is correct
24 Correct 7 ms 7372 KB Output is correct
25 Correct 7 ms 7372 KB Output is correct
26 Correct 8 ms 7372 KB Output is correct
27 Correct 7 ms 7372 KB Output is correct
28 Correct 8 ms 7372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7244 KB Output is correct
2 Correct 6 ms 7260 KB Output is correct
3 Correct 6 ms 7244 KB Output is correct
4 Correct 6 ms 7244 KB Output is correct
5 Correct 6 ms 7372 KB Output is correct
6 Correct 7 ms 7372 KB Output is correct
7 Correct 7 ms 7408 KB Output is correct
8 Correct 8 ms 7336 KB Output is correct
9 Correct 8 ms 7372 KB Output is correct
10 Correct 48 ms 10844 KB Output is correct
11 Correct 65 ms 11184 KB Output is correct
12 Correct 85 ms 11200 KB Output is correct
13 Correct 68 ms 11336 KB Output is correct
14 Correct 128 ms 11344 KB Output is correct
15 Correct 6 ms 7372 KB Output is correct
16 Correct 10 ms 7380 KB Output is correct
17 Correct 7 ms 7372 KB Output is correct
18 Correct 7 ms 7372 KB Output is correct
19 Correct 7 ms 7372 KB Output is correct
20 Correct 6 ms 7372 KB Output is correct
21 Correct 7 ms 7372 KB Output is correct
22 Correct 6 ms 7356 KB Output is correct
23 Correct 6 ms 7372 KB Output is correct
24 Correct 6 ms 7372 KB Output is correct
25 Correct 6 ms 7372 KB Output is correct
26 Correct 6 ms 7372 KB Output is correct
27 Correct 8 ms 7372 KB Output is correct
28 Correct 6 ms 7324 KB Output is correct
29 Correct 7 ms 7372 KB Output is correct
30 Correct 7 ms 7372 KB Output is correct
31 Correct 8 ms 7372 KB Output is correct
32 Correct 7 ms 7372 KB Output is correct
33 Correct 8 ms 7372 KB Output is correct
34 Correct 13 ms 8012 KB Output is correct
35 Correct 68 ms 11328 KB Output is correct
36 Correct 64 ms 11344 KB Output is correct
37 Correct 61 ms 11336 KB Output is correct
38 Correct 70 ms 11336 KB Output is correct
39 Correct 60 ms 11312 KB Output is correct
40 Correct 57 ms 11100 KB Output is correct
41 Correct 79 ms 11376 KB Output is correct
42 Correct 65 ms 11328 KB Output is correct
43 Correct 95 ms 11356 KB Output is correct
44 Correct 72 ms 11332 KB Output is correct
45 Execution timed out 2079 ms 13944 KB Time limit exceeded
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7260 KB Output is correct
2 Correct 6 ms 7244 KB Output is correct
3 Correct 6 ms 7244 KB Output is correct
4 Correct 6 ms 7372 KB Output is correct
5 Correct 7 ms 7372 KB Output is correct
6 Correct 7 ms 7408 KB Output is correct
7 Correct 8 ms 7336 KB Output is correct
8 Correct 8 ms 7372 KB Output is correct
9 Correct 48 ms 10844 KB Output is correct
10 Correct 65 ms 11184 KB Output is correct
11 Correct 85 ms 11200 KB Output is correct
12 Correct 68 ms 11336 KB Output is correct
13 Correct 128 ms 11344 KB Output is correct
14 Correct 96 ms 10968 KB Output is correct
15 Correct 554 ms 12864 KB Output is correct
16 Correct 578 ms 12700 KB Output is correct
17 Correct 501 ms 12864 KB Output is correct
18 Execution timed out 2075 ms 12880 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7244 KB Output is correct
2 Correct 6 ms 7260 KB Output is correct
3 Correct 6 ms 7244 KB Output is correct
4 Correct 6 ms 7244 KB Output is correct
5 Correct 6 ms 7372 KB Output is correct
6 Correct 7 ms 7372 KB Output is correct
7 Correct 7 ms 7408 KB Output is correct
8 Correct 8 ms 7336 KB Output is correct
9 Correct 8 ms 7372 KB Output is correct
10 Correct 48 ms 10844 KB Output is correct
11 Correct 65 ms 11184 KB Output is correct
12 Correct 85 ms 11200 KB Output is correct
13 Correct 68 ms 11336 KB Output is correct
14 Correct 128 ms 11344 KB Output is correct
15 Correct 96 ms 10968 KB Output is correct
16 Correct 554 ms 12864 KB Output is correct
17 Correct 578 ms 12700 KB Output is correct
18 Correct 501 ms 12864 KB Output is correct
19 Execution timed out 2075 ms 12880 KB Time limit exceeded