답안 #1097129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097129 2024-10-06T07:45:15 Z vivkostov 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    /*#ifdef ONLINE_JUDGE
    freopen("taxi.in", "r", stdin);
    freopen("taxi.out", "w", stdout);
    #endif
    */
}
struct cell
{
    int to,cost;
};
int n,m,l,a[200005],b[200005],t[200005],used[200005],lead[200005],dp[200005],mid,mind1,mind2,mind3;
vector<cell>v[200005];
void read()
{
    cin>>n>>m>>l;
    for(int i=0;i<m;i++)
    {
        cin>>a[i]>>b[i]>>t[i];
    }
}
void make_dp(int beg)
{
    used[beg]=1;
    cell w;
    for(int i=0;i<v[beg].size();i++)
    {
        w=v[beg][i];
        if(!used[w.to])
        {
            make_dp(w.to);
            dp[beg]=max(dp[beg],dp[w.to]+w.cost);
        }
    }
}
void find_mid(int beg,int izm)
{
    used[beg]=1;
    cell w;
    int ma=0,sma=0;
    cell ind;
    for(int i=0;i<v[beg].size();i++)
    {
        w=v[beg][i];
        if(dp[w.to]>ma)
        {
            ma=dp[w.to];
            ind=w;
        }
    }
    for(int i=0;i<v[beg].size();i++)
    {
        w=v[beg][i];
        if(w.to!=ind.to&&dp[w.to]+w.cost>sma)
        {
            sma=dp[w.to]+w.cost;
        }
    }
    izm=max(izm,sma)+ind.cost;
    if(dp[beg]<=max(izm,ma))
    {
        mid=beg;
    }
    else
    {
        find_mid(w.to,izm);
    }
}
void make_lead(int beg,int le)
{
    used[beg]=2;
    lead[beg]=le;
    cell w;
    for(int i=0;i<v[beg].size();i++)
    {
        w=v[beg][i];
        if(used[w.to]<2)
        {
            make_lead(w.to,le);
        }
    }
}
void find_max_lead()
{
    int ma=0,ind=0;
    for(int i=0;i<n;i++)
    {
        if(ma<dp[lead[i]])
        {
            ma=dp[lead[i]];
            ind=lead[i];
        }
    }
    mind1=ind;
    ind=0;
    ma=0;
    for(int i=0;i<n;i++)
    {
        if(lead[i]!=mind1&&ma<dp[lead[i]])
        {
            ma=dp[lead[i]];
            ind=lead[i];
        }
    }
    mind2=ind;
    ind=0;
    ma=0;
    for(int i=0;i<n;i++)
    {
        if(lead[i]!=mind1&&lead[i]!=mind2&&ma<dp[lead[i]])
        {
            ma=dp[lead[i]];
            ind=lead[i];
        }
    }
    mind3=ind;
}
int travelTime(int N,int M,int L,int A[],int B[],int T[])
{
    n=N;
    m=M;
    l=L;
    for(int i=0;i<m;i++)
    {
        a[i]=A[i];
        b[i]=B[i];
        t[i]=T[i];
        cell g;
        g.to=b[i];
        g.cost=t[i];
        v[a[i]].push_back(g);
        g.to=a[i];
        v[b[i]].push_back(g);
    }
    for(int i=0;i<n;i++)
    {
        if(!used[i])make_dp(i);
    }
    memset(used,0,sizeof(used));
    for(int i=0;i<n;i++)
    {
        if(!used[i])
        {
            find_mid(i,0);
            make_lead(i,mid);
            mid=0;
        }
    }
    memset(used,0,sizeof(used));
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++)
    {
        if(!used[lead[i]])make_dp(lead[i]);
    }
    find_max_lead();
    return max(dp[mind1]+dp[mind2]+l,dp[mind2]+dp[mind3]+2*l);
}
/*int main()
{
    speed();
    read();
    travelTime(n,m,l,a,b,t);
    return 0;
}
*/

Compilation message

dreaming.cpp: In function 'void make_dp(int)':
dreaming.cpp:33:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<cell>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for(int i=0;i<v[beg].size();i++)
      |                 ~^~~~~~~~~~~~~~
dreaming.cpp: In function 'void find_mid(int, int)':
dreaming.cpp:49:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<cell>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(int i=0;i<v[beg].size();i++)
      |                 ~^~~~~~~~~~~~~~
dreaming.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<cell>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for(int i=0;i<v[beg].size();i++)
      |                 ~^~~~~~~~~~~~~~
dreaming.cpp: In function 'void make_lead(int, int)':
dreaming.cpp:81:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<cell>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for(int i=0;i<v[beg].size();i++)
      |                 ~^~~~~~~~~~~~~~
dreaming.cpp: In function 'void find_mid(int, int)':
dreaming.cpp:66:21: warning: 'ind.cell::cost' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |     izm=max(izm,sma)+ind.cost;
      |         ~~~~~~~~~~~~^~~~~~~~~
dreaming.cpp:67:14: warning: 'w.cell::to' may be used uninitialized in this function [-Wmaybe-uninitialized]
   67 |     if(dp[beg]<=max(izm,ma))
      |        ~~~~~~^
dreaming.cpp:61:9: warning: 'ind.cell::to' may be used uninitialized in this function [-Wmaybe-uninitialized]
   61 |         if(w.to!=ind.to&&dp[w.to]+w.cost>sma)
      |         ^~
/usr/bin/ld: /tmp/ccxKgpAt.o: in function `main':
grader.c:(.text.startup+0xd1): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status