Submission #981043

# Submission time Handle Problem Language Result Execution time Memory
981043 2024-05-12T18:17:46 Z Abito Swapping Cities (APIO20_swap) C++17
0 / 100
2000 ms 13972 KB
#include "swap.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using namespace std;
const int NN=1e5+5;
int n,m,vis[NN],mid,xx,yy;
vector<pair<int,int>> adj[NN];
void dfs(int x){
    vis[x]++;
    if (x==yy) return;
    for (auto u:adj[x]){
        if (vis[u.F]==2 || u.S>mid) continue;
        dfs(u.F);
    }return;
}
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++){
        adj[U[i]].pb({V[i],W[i]});
        adj[V[i]].pb({U[i],W[i]});
    }
    return;
}

int getMinimumFuelCapacity(int X, int Y) {
    int l=1,r=1e9,ans=-1;
    mid=(l+r)/2;
    while (l<=r){
        mid=(l+r)/2;
        xx=X,yy=Y;
        bool ok=false;
        for (int i=0;i<n;i++) vis[i]=0;
        vis[X]=1;
        dfs(X);
        ok|=(vis[Y]==2);
        swap(xx,yy);
        for (int i=0;i<n;i++) vis[i]=0;
        vis[Y]=1;
        dfs(Y);
        ok|=(vis[X]==2);
        if (ok){
            ans=mid;
            r=mid-1;
        }else l=mid+1;
    }return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2808 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Incorrect 2 ms 2652 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2808 KB Output is correct
3 Execution timed out 2083 ms 13972 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2808 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Incorrect 2 ms 2652 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2808 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Incorrect 2 ms 2652 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2808 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Incorrect 2 ms 2652 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2808 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Incorrect 2 ms 2652 KB Output isn't correct
5 Halted 0 ms 0 KB -