답안 #741635

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
741635 2023-05-14T13:38:54 Z vjudge1 꿈 (IOI13_dreaming) C++17
14 / 100
232 ms 28784 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;

vector<pair<int, int> > adj[100000];
map<pair<int, int>, int> edges;
vector<int> subgraphs[100000];
bool visited[100000]={false};

void findsubgraphs(int x, int k)
{
    if (visited[x])
        return;
    visited[x]=true;
    subgraphs[k].push_back(x);
    for (auto edge : adj[x])
        if (!visited[edge.first])
            findsubgraphs(edge.first, k);

    return;
}

pair<int, int> findfarthest(int x, int t)
{
    pair<int, int> farthest={0, x};
    for (auto edge : adj[x])
    {
        int y=edge.first;
        int v=edge.second;
        if (y==t)
            continue;
        auto t=findfarthest(y, x);
        if (t.first+v>farthest.first)
            farthest={t.first+v, t.second};
    }

    return farthest;
}

bool findpath(int x, int t, int y, vector<int> &path)
{
    path.push_back(x);
    if (x==y)
        return true;
    for (auto edge : adj[x])
    {
        if (edge.first==t)
            continue;
        if (findpath(edge.first, x, y, path))
            return true;
    }
    path.pop_back();

    return false;
}

int travelTime(int n, int m, int l, int edgex[], int edgey[], int edgev[])
{
    int k=0, x, y, v, sum, maxdistance=0, i, j;
    for (i=0; i<m; i++)
    {
        x=edgex[i];
        y=edgey[i];
        v=edgev[i];
        adj[x].push_back({y, v});
        adj[y].push_back({x, v});
        edges[{x, y}]=v;
        edges[{y, x}]=v;
    }
    for (i=0; i<m; i++)
    {
        if (visited[i])
            continue;
        findsubgraphs(i, k);
        k=k+1;
    }
    pair<int, int> distances[k];
    for (i=0; i<k; i++)
    {
        x=findfarthest(subgraphs[i][0], -1).second;
        y=findfarthest(x, -1).second;
        vector<int> path;
        findpath(x, -1, y, path);
        sum=0;
        for (j=0; j<path.size()-1; j++)
            sum=sum+edges[{path[j], path[j+1]}];
        distances[i].first=0;
        distances[i].second=sum;
        for (j=0; j<path.size()-1; j++)
        {
            int nextsum1=distances[i].first+edges[{path[j], path[j+1]}];
            int nextsum2=distances[i].second-edges[{path[j], path[j+1]}];
            if (abs(nextsum1-nextsum2)>abs(distances[i].first-distances[i].second))
                break;
            distances[i].first=nextsum1;
            distances[i].second=nextsum2;
        }
        if (distances[i].second>distances[i].first)
            swap(distances[i].first, distances[i].second);
    }
    sort(distances, distances+k);
    for (i=0; i<k; i++)
        maxdistance=max(maxdistance, distances[i].first+distances[i].second);
    if (k>=2)
        maxdistance=max(maxdistance, distances[k-2].first+distances[k-1].first+l);
    if (k>=3)
        maxdistance=max(maxdistance, distances[k-2].first+distances[k-3].first+2*l);

    return maxdistance;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:85:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         for (j=0; j<path.size()-1; j++)
      |                   ~^~~~~~~~~~~~~~
dreaming.cpp:89:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         for (j=0; j<path.size()-1; j++)
      |                   ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 195 ms 28784 KB Output is correct
2 Correct 198 ms 28620 KB Output is correct
3 Correct 111 ms 20388 KB Output is correct
4 Correct 20 ms 8436 KB Output is correct
5 Correct 15 ms 7112 KB Output is correct
6 Correct 32 ms 10280 KB Output is correct
7 Correct 3 ms 5076 KB Output is correct
8 Correct 104 ms 14012 KB Output is correct
9 Correct 136 ms 17180 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 189 ms 21176 KB Output is correct
12 Correct 232 ms 24940 KB Output is correct
13 Correct 3 ms 5204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Incorrect 2 ms 4948 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 195 ms 28784 KB Output is correct
2 Correct 198 ms 28620 KB Output is correct
3 Correct 111 ms 20388 KB Output is correct
4 Correct 20 ms 8436 KB Output is correct
5 Correct 15 ms 7112 KB Output is correct
6 Correct 32 ms 10280 KB Output is correct
7 Correct 3 ms 5076 KB Output is correct
8 Correct 104 ms 14012 KB Output is correct
9 Correct 136 ms 17180 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 189 ms 21176 KB Output is correct
12 Correct 232 ms 24940 KB Output is correct
13 Correct 3 ms 5204 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 3 ms 4952 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 2 ms 4948 KB Output is correct
28 Incorrect 2 ms 4948 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 12388 KB Output is correct
2 Incorrect 59 ms 12364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Incorrect 2 ms 4948 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 195 ms 28784 KB Output is correct
2 Correct 198 ms 28620 KB Output is correct
3 Correct 111 ms 20388 KB Output is correct
4 Correct 20 ms 8436 KB Output is correct
5 Correct 15 ms 7112 KB Output is correct
6 Correct 32 ms 10280 KB Output is correct
7 Correct 3 ms 5076 KB Output is correct
8 Correct 104 ms 14012 KB Output is correct
9 Correct 136 ms 17180 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 189 ms 21176 KB Output is correct
12 Correct 232 ms 24940 KB Output is correct
13 Correct 3 ms 5204 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 3 ms 4952 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 2 ms 4948 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 2 ms 4948 KB Output is correct
28 Incorrect 2 ms 4948 KB Output isn't correct
29 Halted 0 ms 0 KB -