Submission #962102

# Submission time Handle Problem Language Result Execution time Memory
962102 2024-04-13T07:04:58 Z n3rm1n Dreaming (IOI13_dreaming) C++17
0 / 100
1000 ms 13208 KB
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
const int MAXN = 1e5 + 10;
vector < pair < int, int > > g[MAXN];
int mark[MAXN];
int used[MAXN];
void dfs0(int beg)
{
    mark[beg] = 1;
    used[beg] = 1;
    int nb;
    for (int i = 0; i < g[beg].size(); ++ i)
    {
        nb = g[beg][i].first;
        if(!used[nb])
            dfs0(nb);
    }
}
int maxdist = 0;
int dfs(int beg)
{
    used[beg] = 1;
    int nb, distt;
    int maxx = 0;
    for (int i = 0; i < g[beg].size(); ++ i)
    {
        nb = g[beg][i].first;
        distt = g[beg][i].second;
        if(!used[nb])maxx = max(maxx, dfs(nb)+distt);
    }
    return maxx;
}
int travelTime(int N,int M, int L, int A[],int B[], int T[])
{
    for (int i = 0; i < M; ++ i)
    {
        g[A[i]].push_back(make_pair(B[i], T[i]));
        g[B[i]].push_back(make_pair(A[i], T[i]));
    }
    int n = N;
    dfs0(1);
    int marked1 = 0, marked0 = 0;
    int mindist1 = 1e17, mindist2 = 1e17;
    int currmax;
    int index1 = 0, index2 = 0;
    for (int i = 1; i <= n; ++ i)
    {
        if(mark[i])
        {
            memset(used, 0 ,sizeof(used));

            currmax = dfs(i);
            if(currmax < mindist1)
            {
                mindist1 = currmax;
                index1 = i;
            }
        }
        else
        {
            memset(used, 0 ,sizeof(used));

            currmax = dfs(i);
            if(currmax < mindist2)
            {
                mindist2 = currmax;
                index2 = i;
            }
        }

    }
    g[index1].push_back(make_pair(index2, L));
    g[index2].push_back(make_pair(index1, L));
    int ans = 0;
    for (int i = 1; i <= n; ++ i)
    {
        memset(used, 0, sizeof(used));
        ans = max(ans, dfs(i));
    }
    return ans;
}

Compilation message

dreaming.cpp: In function 'void dfs0(int)':
dreaming.cpp:13:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for (int i = 0; i < g[beg].size(); ++ i)
      |                     ~~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs(int)':
dreaming.cpp:26:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int i = 0; i < g[beg].size(); ++ i)
      |                     ~~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:44:20: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+17' to '2147483647' [-Woverflow]
   44 |     int mindist1 = 1e17, mindist2 = 1e17;
      |                    ^~~~
dreaming.cpp:44:37: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+17' to '2147483647' [-Woverflow]
   44 |     int mindist1 = 1e17, mindist2 = 1e17;
      |                                     ^~~~
dreaming.cpp:43:9: warning: unused variable 'marked1' [-Wunused-variable]
   43 |     int marked1 = 0, marked0 = 0;
      |         ^~~~~~~
dreaming.cpp:43:22: warning: unused variable 'marked0' [-Wunused-variable]
   43 |     int marked1 = 0, marked0 = 0;
      |                      ^~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1035 ms 13208 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4692 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Incorrect 2 ms 4540 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1035 ms 13208 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 950 ms 6620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4692 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Incorrect 2 ms 4540 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1035 ms 13208 KB Time limit exceeded
2 Halted 0 ms 0 KB -