답안 #679892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
679892 2023-01-09T15:22:49 Z tigar 꿈 (IOI13_dreaming) C++14
0 / 100
43 ms 14172 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;

vector<pair<int, int> >graff[100010];
int dist[100010], dist2[100010], anc[100010];
bool check[100010], check2[100010];
vector<int>LongestPaths;
int v, d, dmx;

void dfs(int cvor)
{
    check[cvor]=true;
    if(dist[cvor]>d){v=cvor; d=dist[cvor];}
    for(int i=0; i<graff[cvor].size(); i++)
    {
        if(!check[graff[cvor][i].first])
        {
            dist[graff[cvor][i].first]=dist[cvor]+graff[cvor][i].second;
            dfs(graff[cvor][i].first);
        }
    }
}

void dfs2(int cvor)
{
    check2[cvor]=true;
    if(dist2[cvor]>d){v=cvor; d=dist2[cvor];}
    for(int i=0; i<graff[cvor].size(); i++)
    {
        if(!check2[graff[cvor][i].first])
        {
            dist2[graff[cvor][i].first]=dist2[cvor]+graff[cvor][i].second;
            anc[graff[cvor][i].first]=cvor;
            dfs2(graff[cvor][i].first);
        }
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
    for(int i=0; i<M; i++)
    {
        graff[A[i]].push_back({B[i], T[i]});
        graff[B[i]].push_back({A[i], T[i]});
    }
    for(int i=0; i<N; i++)
    {
        if(!check[i])
        {
            v=i; dfs(i);
            d=0; int pp=v;
            dfs2(v);
            int predak=v;
            vector<int>putic;
            while(predak!=pp){putic.push_back(predak); predak=anc[predak];}
            putic.push_back(predak);
            int rez=INT_MAX;
            for(int j=0; j<putic.size(); j++)
            {
                //cout<<putic[j]<<" ";
                int bg=putic[j];
                rez=min(rez, max(dist2[bg], d-dist2[bg]));
            }
            LongestPaths.push_back(rez);
            dmx=max(d, dmx);
            d=0; v=0;
        }
    }
    sort(LongestPaths.begin(), LongestPaths.end());
    int lngt=LongestPaths.size()-1;
    return max(dmx, max(LongestPaths[lngt]+L+LongestPaths[lngt-1], LongestPaths[lngt-1]+LongestPaths[lngt-2]+2*L));
}

/*int main()
{
    int N, M, L;
    cin>>N>>M>>L;
    int A[100], B[100], T[100];
    for(int i=0; i<M; i++)cin>>A[i]>>B[i]>>T[i];
    cout<<travelTime(N, M, L, A, B, T);
}
/*12 8 2
0 8 4
8 2 2
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 3*/

Compilation message

dreaming.cpp:83:1: warning: "/*" within comment [-Wcomment]
   83 | /*12 8 2
      |  
dreaming.cpp: In function 'void dfs(int)':
dreaming.cpp:15:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i=0; i<graff[cvor].size(); i++)
      |                  ~^~~~~~~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs2(int)':
dreaming.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i=0; i<graff[cvor].size(); i++)
      |                  ~^~~~~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:59:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |             for(int j=0; j<putic.size(); j++)
      |                          ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 14160 KB Output is correct
2 Correct 41 ms 14172 KB Output is correct
3 Correct 27 ms 10088 KB Output is correct
4 Correct 7 ms 4308 KB Output is correct
5 Correct 5 ms 3540 KB Output is correct
6 Correct 10 ms 5176 KB Output is correct
7 Incorrect 1 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Incorrect 1 ms 2644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 14160 KB Output is correct
2 Correct 41 ms 14172 KB Output is correct
3 Correct 27 ms 10088 KB Output is correct
4 Correct 7 ms 4308 KB Output is correct
5 Correct 5 ms 3540 KB Output is correct
6 Correct 10 ms 5176 KB Output is correct
7 Incorrect 1 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 6628 KB Output is correct
2 Correct 19 ms 6636 KB Output is correct
3 Correct 19 ms 6616 KB Output is correct
4 Correct 19 ms 6612 KB Output is correct
5 Correct 20 ms 6556 KB Output is correct
6 Correct 30 ms 7024 KB Output is correct
7 Correct 21 ms 6744 KB Output is correct
8 Correct 19 ms 6568 KB Output is correct
9 Correct 18 ms 6488 KB Output is correct
10 Correct 20 ms 6748 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 7 ms 4304 KB Output is correct
13 Correct 7 ms 4428 KB Output is correct
14 Correct 7 ms 4384 KB Output is correct
15 Correct 6 ms 4428 KB Output is correct
16 Correct 6 ms 4304 KB Output is correct
17 Correct 6 ms 3780 KB Output is correct
18 Correct 7 ms 4556 KB Output is correct
19 Correct 6 ms 4304 KB Output is correct
20 Incorrect 1 ms 2644 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Incorrect 1 ms 2644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 14160 KB Output is correct
2 Correct 41 ms 14172 KB Output is correct
3 Correct 27 ms 10088 KB Output is correct
4 Correct 7 ms 4308 KB Output is correct
5 Correct 5 ms 3540 KB Output is correct
6 Correct 10 ms 5176 KB Output is correct
7 Incorrect 1 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -