Submission #400076

# Submission time Handle Problem Language Result Execution time Memory
400076 2021-05-07T10:09:55 Z victoriad Dreaming (IOI13_dreaming) C++14
0 / 100
1000 ms 9500 KB
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>
#include <iomanip>
#include <fstream>
#include "dreaming.h"
using namespace std;


void dfs(vector<int>&con,vector<vector<pair<int,int> > >&g,int nodo){
    con[nodo]=1;
    for(pair<int,int>c: g[nodo]){
        if(con[c.first]==0){
            dfs(con,g,c.first);
        }
    }
}
int bfs(vector<vector<pair<int,int> > >&g,int r,int m){
   int a=0;
   vector<int>d(g.size(),1e9);
   queue<int>cola;
   cola.push(r);
    d[r]=0;
     while(!cola.empty()){
        int na=cola.front();
          cola.pop();
          for(pair<int,int> c: g[na]){
            if(d[c.first]>d[na]+c.second){
                 d[c.first]=d[na]+c.second;
                  if(d[c.first]>a){
                    a=d[c.first];
                    if(a>m){
                      return m;
                    }
                  }
                  cola.push(c.first);
                    }
                }
            }
            return a;
}
int menormayor(vector<int>&con,vector<vector<pair<int,int> > >&g,int n){
    int f=1e9,s=1e9;
    for(int i=0;i<n;i++){
        if(con[i]==1){
          int a=bfs(g,i,f);
            if(a<f)f=a;
        }
        else{
           int a=bfs(g,i,s);
          if(a<s)s=a;
        }
    }
    return s+f;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    vector<vector<pair<int,int> > >g(N);
    vector<int>con(N,0);
    for(int i=0;i<N;i++){
        int a=A[i],b=B[i],c=T[i];
        g[a].push_back(make_pair(b,c));
        g[b].push_back(make_pair(a,c));
    }
    if(M==N-2){
        dfs(con,g,0);
        return menormayor(con,g,N)+L;
    }
    return 42;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 9500 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 9500 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 6392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 9500 KB Time limit exceeded
2 Halted 0 ms 0 KB -