Submission #1102594

# Submission time Handle Problem Language Result Execution time Memory
1102594 2024-10-18T11:55:45 Z asli_bg Crocodile's Underground City (IOI11_crocodile) C++11
0 / 100
2000 ms 10576 KB
#pragma GCC optimize("O3,unroll-loops")
#include "crocodile.h" 
 
#include<bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define FOR(i,a) for(int i=0;i<(a);i++)
#define FORE(i,a,b) for(int i=(a);i<(b);i++)
 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vii;
 
#define cont(x) for(auto el:x) {cout<<el<<' ';} cout<<endl;
#define endl '\n'
#define contp(x) for(auto el:x) {cout<<el.fi<<'-'<<el.se<<' ';} cout<<endl;
#define pb push_back
 
#define sp <<' '<<
 
#define DEBUG(x) {cout<<(#x) sp x<<endl;}
 
const int MAXN=1e5+5;
const int INF=1e9;

int n,m,k;
vii adj[MAXN];
vi ex;
//her node için min 3 yolu tut, nereden geldiğiyle birlikte
multiset<pii> yol[MAXN];
bool vis[MAXN];
bool cikis[MAXN];
 
void bfs(){
    set<pii> s;
    for(auto el:ex){
        s.insert({0,el});
        yol[el].insert({0,el});
    }
 
    while(!s.empty()){
        auto el=*s.begin();
        s.erase(*s.begin());
 
        int dd=el.fi;
        int nd=el.se;
 
        for(auto temp:adj[nd]){
            int kom=temp.fi;
            int cost=temp.se;
 
            if(cikis[kom]) continue;
            s.erase({yol[kom].begin()->fi,kom});
            yol[kom].insert({dd+cost,nd});
            //her komsu node için bir tane min degerini sadece tut
            if(yol[kom].size()>3){
                //sonuncu elemanı sil
                yol[kom].erase(yol[kom].find(*yol[kom].rbegin()));
            }
            s.insert({yol[kom].begin()->fi,kom});
        }
    }  
}
 
int cev;
 
void dfs(int nd,int ata,int dd){
    vis[nd]=true;
 
    //min path
    int mn=yol[nd].begin()->se;
    if(mn==nd){
        cev=min(dd,cev);
        return;
    }
 
    for(auto el:adj[nd]){
        int kom=el.fi;
        int cost=el.se;
        if(kom==ata or kom==mn) continue;
      	if(vis[kom]) continue;
        dfs(kom,nd,dd+cost);
    }
}
 
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
    n=N;
    m=M;
    k=K;
    FOR(i,m){
        int bir=R[i][0];
        int iki=R[i][1];
        adj[bir].pb({iki,L[i]});
        adj[iki].pb({bir,L[i]});
    }
 
    FOR(i,k){
        cikis[P[i]]=true;
        ex.pb(P[i]);
    }
 
    bfs();
    cev=INF;
    
    memset(vis,0,sizeof vis);
    dfs(0,-1,0);
 
    return cev;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 2028 ms 10576 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2028 ms 10576 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2028 ms 10576 KB Time limit exceeded
2 Halted 0 ms 0 KB -