Submission #410767

# Submission time Handle Problem Language Result Execution time Memory
410767 2021-05-23T17:02:01 Z LouayFarah Race (IOI11_race) C++14
21 / 100
3000 ms 202292 KB
#include <bits/stdc++.h>
#include "race.h"
 
using namespace std;
 
void depth(vector<pair<int, int>> adj[], int u, int e, vector<int> &cnt)
{
    for(auto v: adj[u])
    {
        if(v.first!=e)
        {
            cnt[v.first] = cnt[u]+v.second;
            depth(adj, v.first, u, cnt);
        }
    }
}
 
void all_pairs_distance(vector<pair<int, int>> adj[], int N, vector<vector<int>> &cnt)
{
    for(int i = 0; i<N; i++)
    {
        vector<int> temp(N);
        depth(adj, i, -1, temp);
        cnt.push_back(temp);
    }
}
 
void depth2(vector<pair<int, int>> adj[], int u, int e, vector<int> &cnt)
{
    for(auto v: adj[u])
    {
        if(v.first!=e)
        {
            cnt[v.first] = cnt[u]+1;
            depth2(adj, v.first, u, cnt);
        }
    }
}
 
void all_pairs_distance2(vector<pair<int, int>> adj[], int N, vector<vector<int>> &cnt)
{
    for(int i = 0; i<N; i++)
    {
        vector<int> temp(N);
        depth2(adj, i, -1, temp);
        cnt.push_back(temp);
    }
}
 
int best_path(int N, int K, int H[][2], int L[])
{
    vector<pair<int, int>> adj[N];
    for(int i = 0; i<N-1; i++)
    {
        adj[H[i][0]].push_back(make_pair(H[i][1], L[i]));
        adj[H[i][1]].push_back(make_pair(H[i][0], L[i]));
    }
 
    vector<vector<int>> cnt;
    all_pairs_distance(adj, N, cnt);
 
    vector<vector<int>> cnt2;
    all_pairs_distance2(adj, N, cnt2);
 
    bool flag = false;
    int res = 1e8;
    for(int i = 0; i<N; i++)
    {
        for(int j = 0; j<N; j++)
        {
            if(cnt[i][j]==K)
                res = min(res, cnt2[i][j]), flag = true;
        }
    }
 
    if(!flag)
        return -1;
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 376 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 376 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 33 ms 8260 KB Output is correct
22 Correct 34 ms 8252 KB Output is correct
23 Correct 35 ms 8272 KB Output is correct
24 Correct 39 ms 8284 KB Output is correct
25 Correct 33 ms 8256 KB Output is correct
26 Correct 33 ms 8260 KB Output is correct
27 Correct 32 ms 8172 KB Output is correct
28 Correct 32 ms 8176 KB Output is correct
29 Correct 33 ms 8236 KB Output is correct
30 Correct 33 ms 8212 KB Output is correct
31 Correct 32 ms 8292 KB Output is correct
32 Correct 37 ms 8312 KB Output is correct
33 Correct 42 ms 8260 KB Output is correct
34 Correct 25 ms 7040 KB Output is correct
35 Correct 24 ms 6696 KB Output is correct
36 Correct 20 ms 5752 KB Output is correct
37 Correct 20 ms 5780 KB Output is correct
38 Correct 25 ms 7168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 376 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Execution timed out 3095 ms 202292 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 376 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 33 ms 8260 KB Output is correct
22 Correct 34 ms 8252 KB Output is correct
23 Correct 35 ms 8272 KB Output is correct
24 Correct 39 ms 8284 KB Output is correct
25 Correct 33 ms 8256 KB Output is correct
26 Correct 33 ms 8260 KB Output is correct
27 Correct 32 ms 8172 KB Output is correct
28 Correct 32 ms 8176 KB Output is correct
29 Correct 33 ms 8236 KB Output is correct
30 Correct 33 ms 8212 KB Output is correct
31 Correct 32 ms 8292 KB Output is correct
32 Correct 37 ms 8312 KB Output is correct
33 Correct 42 ms 8260 KB Output is correct
34 Correct 25 ms 7040 KB Output is correct
35 Correct 24 ms 6696 KB Output is correct
36 Correct 20 ms 5752 KB Output is correct
37 Correct 20 ms 5780 KB Output is correct
38 Correct 25 ms 7168 KB Output is correct
39 Execution timed out 3095 ms 202292 KB Time limit exceeded
40 Halted 0 ms 0 KB -