Submission #336414

# Submission time Handle Problem Language Result Execution time Memory
336414 2020-12-15T08:56:33 Z sumit_kk10 Dreaming (IOI13_dreaming) C++14
0 / 100
108 ms 38108 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 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]);
            }
        }
    }
    for(auto k : connected)
        if(level[k] == mx_lvl)
            centres.insert(k);
}

void dfs(int source, int longest){
    vis[source] = 1;
    connected.push_back(source);
    if(longest > mx){
        mx = longest;
        node = source;
    }
    for(auto k : graph[source])
        if(!vis[k.first]) 
            dfs(k.first, longest + 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});
        degree[u]++;
        degree[v]++;
    }
    vector<int> diameters;
    for(int i = 0; i < N; ++i){
        if(!vis[i]){
            node = i;
            connected.clear();
            dfs(i, 0);
            for(auto k : connected){
                if(degree[k] == 1)
                    q.push(k);
                vis[k] = 0;
            }
            mx = 0;
            connected.clear();
            dfs(node, 0);
            diameters.push_back(mx);
            bfs();
            mx_lvl = 0, mx = 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});
    }
    mx = 0;
    sort(diameters.rbegin(), diameters.rend());
    memset(vis, 0, sizeof(vis));
    dfs(0, 0);
    memset(vis, 0, sizeof(vis));
    mx = 0;
    dfs(node, 0);
    return max(diameters[0], mx);
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:77:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for(int i = 1; i < centre.size(); ++i){
      |                    ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 107 ms 37816 KB Output is correct
2 Correct 95 ms 37732 KB Output is correct
3 Correct 59 ms 33128 KB Output is correct
4 Correct 25 ms 26776 KB Output is correct
5 Correct 25 ms 26092 KB Output is correct
6 Correct 34 ms 27884 KB Output is correct
7 Incorrect 19 ms 24812 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 107 ms 37816 KB Output is correct
2 Correct 95 ms 37732 KB Output is correct
3 Correct 59 ms 33128 KB Output is correct
4 Correct 25 ms 26776 KB Output is correct
5 Correct 25 ms 26092 KB Output is correct
6 Correct 34 ms 27884 KB Output is correct
7 Incorrect 19 ms 24812 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 107 ms 37816 KB Output is correct
2 Correct 95 ms 37732 KB Output is correct
3 Correct 59 ms 33128 KB Output is correct
4 Correct 25 ms 26776 KB Output is correct
5 Correct 25 ms 26092 KB Output is correct
6 Correct 34 ms 27884 KB Output is correct
7 Incorrect 19 ms 24812 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 108 ms 38108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 107 ms 37816 KB Output is correct
2 Correct 95 ms 37732 KB Output is correct
3 Correct 59 ms 33128 KB Output is correct
4 Correct 25 ms 26776 KB Output is correct
5 Correct 25 ms 26092 KB Output is correct
6 Correct 34 ms 27884 KB Output is correct
7 Incorrect 19 ms 24812 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 107 ms 37816 KB Output is correct
2 Correct 95 ms 37732 KB Output is correct
3 Correct 59 ms 33128 KB Output is correct
4 Correct 25 ms 26776 KB Output is correct
5 Correct 25 ms 26092 KB Output is correct
6 Correct 34 ms 27884 KB Output is correct
7 Incorrect 19 ms 24812 KB Output isn't correct
8 Halted 0 ms 0 KB -