Submission #339981

# Submission time Handle Problem Language Result Execution time Memory
339981 2020-12-26T13:15:23 Z iliccmarko Dreaming (IOI13_dreaming) C++14
18 / 100
60 ms 20204 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 1000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define input(n, v) {for(int i = 0;i<n;i++) cin>>v[i];}
#define output(n, v) {for(int i = 0;i<n;i++) cout<<v[i]<<" "; cout<<endl;}
#define single_case solve();
#define line cout<<"------------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); }
int maksd;
const int N = 1e5 + 5;
int vidjen[N];
vector<vector<pair<int, int > > > g(N);
vector<int> v;
int mm, s;
vector<vector<pair<int, int> > > path(N);

void najdalji(int u, int pret, int d)
{
    vidjen[u] = 1;
    if(d>=mm)
    {
        mm = d;
        s = u;
    }
    for(auto x : g[u])
    {
        if(x.first==pret) continue;
        najdalji(x.first, u, x.second+d);
    }
}

bool get_path(int u, int pret, int k, int parent, int d)
{
    if(u==k)
    {
        path[parent].pb({u, d});
        return true;
    }
    for(auto x : g[u])
    {
        if(x.first==pret) continue;
        if(get_path(x.first, u, k, parent, x.second))
        {
            path[parent].pb({u, d});
            return true;
        }
    }
    return false;
}


int travelTime(int n, int m, int l, int a[], int b[], int t[])
{
    for(int i = 0;i<m;i++)
    {
        int x = a[i];
        int y = b[i];
        int l = t[i];
        g[x].pb({y, l});
        g[y].pb({x, l});
    }
    for(int i = 1;i<=n;i++)
    {
        if(vidjen[i]) continue;
        mm = 0;
        s = i;
        int l1;
        najdalji(i, -1, 0);
        l1 = s;
        mm = 0;
        s = l1;
        int l2;
        najdalji(l1, -1, 0);
        l2 = s;
        get_path(l1, -1, l2, i, 0);
        int sum = 0;
        int c;
        int mini = INF;
        int m2;
        for(auto x : path[i]) sum += x.second;
        for(auto x : path[i])
        {
            if(abs(x.second - (sum - x.second)) < mini)
            {
                m2 = max(x.second, sum - x.second);
                mini = abs(x.second - (sum - x.second));
                c = x.first;
            }
        }
        maksd = max(maksd, sum);
        v.pb(m2);
    }
    sort(all(v), greater<int>());
    int ans = maksd;
    if(len(v)==1)
    {
        return ans;
    }
    ans = max(ans, v[0]+v[1]+l);
    if(len(v)>=3)
    {
        ans = max(ans, v[1] + v[2] + 2*l);
    }
    return ans;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:85:13: warning: variable 'c' set but not used [-Wunused-but-set-variable]
   85 |         int c;
      |             ^
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 20204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 20204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 20204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 10348 KB Output is correct
2 Correct 34 ms 10412 KB Output is correct
3 Correct 33 ms 10344 KB Output is correct
4 Correct 35 ms 10344 KB Output is correct
5 Correct 33 ms 10344 KB Output is correct
6 Correct 35 ms 10856 KB Output is correct
7 Correct 34 ms 10600 KB Output is correct
8 Correct 34 ms 10216 KB Output is correct
9 Correct 33 ms 10216 KB Output is correct
10 Correct 34 ms 10472 KB Output is correct
11 Correct 4 ms 4972 KB Output is correct
12 Correct 14 ms 8932 KB Output is correct
13 Correct 15 ms 8932 KB Output is correct
14 Correct 14 ms 8932 KB Output is correct
15 Correct 14 ms 8932 KB Output is correct
16 Correct 14 ms 8932 KB Output is correct
17 Correct 14 ms 8932 KB Output is correct
18 Correct 15 ms 8932 KB Output is correct
19 Correct 14 ms 8932 KB Output is correct
20 Correct 4 ms 4972 KB Output is correct
21 Correct 4 ms 4972 KB Output is correct
22 Correct 4 ms 5100 KB Output is correct
23 Correct 15 ms 8932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 20204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 20204 KB Output isn't correct
2 Halted 0 ms 0 KB -