Submission #336312

# Submission time Handle Problem Language Result Execution time Memory
336312 2020-12-15T04:15:58 Z sumit_kk10 Dreaming (IOI13_dreaming) C++14
0 / 100
1000 ms 36204 KB
#include <bits/stdc++.h>
#include<dreaming.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
vector<pair<long long int, long long int> > graph[N];
bool vis[N];
long long int mx = 0, node1;
vector<int> connected;
 
void dfs(int source, long long int largest){
    vis[source] = 1;
    if(largest >= mx){
        mx = largest;
        node1 = source;
    }
    connected.push_back(source);
    for(auto k : graph[source])
        if(!vis[k.first])
            dfs(k.first, largest + k.second);
}
 
void dfs1(int source, long long int largest){
    vis[source] = 1;
    mx = max(mx, largest);
    for(auto k : graph[source])
        if(!vis[k.first])
            dfs1(k.first, largest + k.second);
}
 
int travelTime(int N, int M, int L, int A[], int B[], int T[]){
    for(int i = 0; i < M; ++i){
        long long int u = A[i], v = B[i], c = T[i];
        graph[u].push_back({v, c});
        graph[v].push_back({u, c});
        // cout << u << ' ' << v << ' ' << c << endl;
    }
    vector<long long int> paths;
    for(int i = 0; i < N; ++i){
        if(!vis[i]){
            dfs(i, 0);
            long long int mn = mx, node = i;
            mx = 0;
            for(int j = 1; j < connected.size(); ++j){
                for(auto k : connected)
                    vis[k] = 0;
                dfs1(connected[j], 0);
                if(mx < mn){
                    node = connected[j];
                    mn = mx;
                }
                mx = 0;
            }
            // cout << node << '\n';
            for(auto k : connected)
                vis[k] = 1;
            paths.push_back(node);
            connected.clear();
        }
    }
    for(int i = 0; i < paths.size() - 1; ++i){
        int u = paths[i], v = paths[i + 1];
        graph[u].push_back({v, L});
        graph[v].push_back({u, L});
    }
    long long int ans = 0; 
    memset(vis, 0, sizeof(vis));
    dfs(0, 0);
    ans = max(ans, mx);
    memset(vis, 0, sizeof(vis));
    mx = 0;
    dfs(node1, 0);
    return max(ans, mx);
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:47:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |             for(int j = 1; j < connected.size(); ++j){
      |                            ~~^~~~~~~~~~~~~~~~~~
dreaming.cpp:64:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for(int i = 0; i < paths.size() - 1; ++i){
      |                    ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 33000 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 33000 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 33000 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 36204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 33000 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 33000 KB Time limit exceeded
2 Halted 0 ms 0 KB -