Submission #838604

# Submission time Handle Problem Language Result Execution time Memory
838604 2023-08-27T12:45:42 Z nnin Dreaming (IOI13_dreaming) C++14
0 / 100
1000 ms 15744 KB
#include "dreaming.h"
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;

vector<pair<int, int>> adj[100005];
vector<int> group[100005];
int maxdis[100005];
bool vis[100005];

int dsu[100005];
int par(int x) {
    if(dsu[x]==x) return x;
    return dsu[x] = par(dsu[x]);
}

void dfs(int cur, int prev, int dis) {
    maxdis[cur] = max(maxdis[cur], dis);
    for(auto next:adj[cur]) {
        if(prev==next.f) continue;
        dfs(next.f, cur, dis+next.s);
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(int i=0;i<N;i++) dsu[i] = i;
    for(int i=0;i<M;i++) {
        adj[A[i]].push_back({B[i], T[i]});
        adj[B[i]].push_back({A[i], T[i]});
        dsu[par(A[i])] = par(B[i]);
    }
    for(int i=0;i<N;i++) group[par(i)].push_back(i);
    int mx = INT_MIN, mx2 = INT_MIN;
    for(int i=0;i<N;i++) {
        if(group[i].empty()) continue;
        for(int j=0;j<group[i].size();j++) {
            int st = -1;
            int curmx = -1;
            for(int k=0;k<group[i].size();k++) {
                if(!vis[group[i][k]] && maxdis[group[i][k]]>curmx) {
                    st = group[i][k];
                    curmx = maxdis[group[i][k]];
                }
            }
            if(st==-1) break;
            dfs(st, -1, 0);
            vis[st] = 1;
        }
        int mngroup = INT_MAX;
        for(int j=0;j<group[i].size();j++) {
            mngroup = min(mngroup, maxdis[group[i][j]]);
        }
        if(mngroup>=mx) {
            mx2 = mx;
            mx = mngroup;
        } else if(mngroup>mx2) {
            mx2 = mngroup;
        }
    }
    if(mx2==INT_MIN) return mx;
    return mx+mx2+L;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for(int j=0;j<group[i].size();j++) {
      |                     ~^~~~~~~~~~~~~~~~
dreaming.cpp:40:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |             for(int k=0;k<group[i].size();k++) {
      |                         ~^~~~~~~~~~~~~~~~
dreaming.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for(int j=0;j<group[i].size();j++) {
      |                     ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 15744 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 5008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 15744 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 10528 KB Output is correct
2 Incorrect 22 ms 10456 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 5008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 15744 KB Time limit exceeded
2 Halted 0 ms 0 KB -