Submission #336408

# Submission time Handle Problem Language Result Execution time Memory
336408 2020-12-15T08:40:53 Z sumit_kk10 Dreaming (IOI13_dreaming) C++14
0 / 100
85 ms 38632 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];
vector<int> diameters, connected;
int mx, node, degree[N], mx_lvl, level[N];
queue<int> q;
set<int> centres;
bool vis[N];

void dfs(int source, int longest){
    vis[source] = 1;
    if(longest > mx){
        mx = longest;
        node = source;
    }
    connected.push_back(source);
    for(auto k : graph[source])
        if(!vis[k.first]) 
            dfs(k.first, longest + k.second);
}

void bfs(){
    while(!q.empty()){
        int node = q.front();
        q.pop();
        for(auto k : graph[node]){
            degree[k.first]--;
            if(degree[k.first] == 1){
                level[k.first] = level[node] + 1;
                q.push(k.first);
                mx_lvl = max(mx_lvl, level[k.first]);
            }
        }
    }
}

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});
        degree[u]++;
        degree[v]++;
    }
    for(int i = 0; i < N; ++i){
        if(!vis[i]){
            connected.clear();
            dfs(i, 0);
            for(auto k : connected)
                if(degree[k] == 1)
                    q.push(k);
            bfs();
            for(auto k : connected){
                if(level[k] == mx_lvl){
                    centres.insert(k);
                    break;
                }
            }
            mx_lvl = 0;
        }
    }
    vector<int> centre;
    for(auto k : centres)
        centre.push_back(k);
    int u = centre[0];
    for(int i = 1; i < centre.size(); ++i){
        int v = centre[i];
        graph[u].push_back({v, L});
        graph[v].push_back({u, L});
    }
    memset(vis, 0, sizeof(vis));
    dfs(0, 0);
    memset(vis, 0, sizeof(vis));
    mx = 0;
    dfs(node, 0);
    return mx;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(int i = 1; i < centre.size(); ++i){
      |                    ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 85 ms 37984 KB Output is correct
2 Correct 82 ms 38632 KB Output is correct
3 Correct 57 ms 34020 KB Output is correct
4 Correct 25 ms 27116 KB Output is correct
5 Correct 27 ms 26368 KB Output is correct
6 Correct 33 ms 28136 KB Output is correct
7 Incorrect 19 ms 24952 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 85 ms 37984 KB Output is correct
2 Correct 82 ms 38632 KB Output is correct
3 Correct 57 ms 34020 KB Output is correct
4 Correct 25 ms 27116 KB Output is correct
5 Correct 27 ms 26368 KB Output is correct
6 Correct 33 ms 28136 KB Output is correct
7 Incorrect 19 ms 24952 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 85 ms 37984 KB Output is correct
2 Correct 82 ms 38632 KB Output is correct
3 Correct 57 ms 34020 KB Output is correct
4 Correct 25 ms 27116 KB Output is correct
5 Correct 27 ms 26368 KB Output is correct
6 Correct 33 ms 28136 KB Output is correct
7 Incorrect 19 ms 24952 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 69 ms 35040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 85 ms 37984 KB Output is correct
2 Correct 82 ms 38632 KB Output is correct
3 Correct 57 ms 34020 KB Output is correct
4 Correct 25 ms 27116 KB Output is correct
5 Correct 27 ms 26368 KB Output is correct
6 Correct 33 ms 28136 KB Output is correct
7 Incorrect 19 ms 24952 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 85 ms 37984 KB Output is correct
2 Correct 82 ms 38632 KB Output is correct
3 Correct 57 ms 34020 KB Output is correct
4 Correct 25 ms 27116 KB Output is correct
5 Correct 27 ms 26368 KB Output is correct
6 Correct 33 ms 28136 KB Output is correct
7 Incorrect 19 ms 24952 KB Output isn't correct
8 Halted 0 ms 0 KB -