Submission #400188

# Submission time Handle Problem Language Result Execution time Memory
400188 2021-05-07T14:06:22 Z victoriad Dreaming (IOI13_dreaming) C++14
0 / 100
1000 ms 10692 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,int x){
    con[nodo]=x;
    for(pair<int,int>c: g[nodo]){
        if(con[c.first]==-1){
            dfs(con,g,c.first,x);
        }
    }
}
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,vector<int>&d,int L){
    int f=1e9,s=1e9;
    for(int i=0;i<n;i++){
        int a=bfs(g,i,d[con[i]]);
        if(d[con[i]]>a)d[con[i]]=a;
    }
    int x=d.size();
    sort(d.rbegin(),d.rend());
    return max((d[0]+d[1]+L),(d[1]+d[2]+2*L));
}
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,-1);
    for(int i=0;i<M;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));
    }
    int c=0;
    for(int i=0;i<N;i++){
      if(con[i]==-1){
        dfs(con,g,i,c);
        c++;
      }
    }
      vector<int>d(c,1e9);
      return menormayor(con,g,N,d,L);
    
}




Compilation message

dreaming.cpp: In function 'int menormayor(std::vector<int>&, std::vector<std::vector<std::pair<int, int> > >&, int, std::vector<int>&, int)':
dreaming.cpp:48:9: warning: unused variable 'f' [-Wunused-variable]
   48 |     int f=1e9,s=1e9;
      |         ^
dreaming.cpp:48:15: warning: unused variable 's' [-Wunused-variable]
   48 |     int f=1e9,s=1e9;
      |               ^
dreaming.cpp:53:9: warning: unused variable 'x' [-Wunused-variable]
   53 |     int x=d.size();
      |         ^
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 10692 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 1087 ms 10692 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 6232 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 1087 ms 10692 KB Time limit exceeded
2 Halted 0 ms 0 KB -