Submission #962084

# Submission time Handle Problem Language Result Execution time Memory
962084 2024-04-13T06:51:52 Z n3rm1n Dreaming (IOI13_dreaming) C++17
Compilation error
0 ms 0 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]);
    }

    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(marked[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 < mindist1)
            {
                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));
    }
    cout << ans << endl;
}

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: At global scope:
dreaming.cpp:34:51: error: expected ',' or '...' before 'int'
   34 | int travelTime(int N,int M, int L, int A[],int B[]int T[])
      |                                                   ^~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*)':
dreaming.cpp:38:43: error: 'T' was not declared in this scope
   38 |         g[A[i]].push_back(make_pair(B[i], T[i]);
      |                                           ^
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:47:26: error: 'n' was not declared in this scope
   47 |     for (int i = 1; i <= n; ++ i)
      |                          ^
dreaming.cpp:49:12: error: 'marked' was not declared in this scope; did you mean 'marked0'?
   49 |         if(marked[i])
      |            ^~~~~~
      |            marked0
dreaming.cpp:71:43: error: 'l' was not declared in this scope
   71 |     g[index1].push_back(make_pair(index2, l));
      |                                           ^
dreaming.cpp:74:26: error: 'n' was not declared in this scope
   74 |     for (int i = 1; i <= n; ++ i)
      |                          ^
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;
      |                      ^~~~~~~
dreaming.cpp:80:1: warning: no return statement in function returning non-void [-Wreturn-type]
   80 | }
      | ^