답안 #453716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
453716 2021-08-04T15:59:27 Z tht2005 꿈 (IOI13_dreaming) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define FORE(i,a) for(auto&i:a)
#define rep(i,a,b,z) for(int i=(a),_b=(b),_z=(z);i<=_b;i+=_z)
#define SZ(a) ((int)a.size())
#define ALL(a) a.begin(),a.end()

#define fs first
#define sc second
typedef pair<int,int> ii;
const int nmax=100010;

int f[nmax],f2[nmax],g[nmax],vst[nmax];
vector<ii>adj[nmax];

void dfs(int u, int p=-1)
{
    vst[u]=*vst;
    f[u]=f2[u]=0;
    FORE(x,adj[u]){
        if(x.sc==p)continue;
        dfs(x.sc,u);
        if(f[u]<f[x.sc]+x.fs){
            f2[u]=f[u];
            f[u]=f[x.sc]+x.fs;
        }
        else if(f2[u]<f[x.sc]+x.fs)
            f2[u]=f[x.sc]+x.fs;
    }
}

void dfs2(int u, int p=-1)
{
    FORE(x,adj[u]){
        if(x.sc==p)continue;
        if(f[u]==f[x.sc]+x.fs)g[x.sc]=max(g[u],f2[u])+x.fs;
        else g[x.sc]=max(g[u],f[u])+x.fs;
        dfs2(x.sc,u);
    }
}

int calc(int n, int l, const vector<int>& a)
{
    int ans=0;
    int pos=max_element(a.begin()+1,a.end())-a.begin();
    FOR(i,1,n)if(i!=pos)ans=max(ans,a[i]+a[pos]+l);
    return ans;
}

int travelTime(int N,int M,int L,int A[],int B[],int T[])
{
    FOR(i,0,M-1){
        ++A[i],++B[i];
        adj[A[i]].push_back({T[i],B[i]});
        adj[B[i]].push_back({T[i],A[i]});
    }
    FOR(i,1,n)if(!vst[i])++*vst,dfs(i),dfs2(i);
    FOR(i,1,n)f[i]=max(f[i],g[i]);
    vector<int>a(*vst+1,0x3f3f3f3f);
    FOR(i,1,n)a[vst[i]]=min(a[vst[i]],f[i]);
    f[0]=calc(*vst,l,a);
    return *max_element(f,f+1+n);
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:60:13: error: 'n' was not declared in this scope
   60 |     FOR(i,1,n)if(!vst[i])++*vst,dfs(i),dfs2(i);
      |             ^
dreaming.cpp:4:38: note: in definition of macro 'FOR'
    4 | #define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
      |                                      ^
dreaming.cpp:61:13: error: 'n' was not declared in this scope
   61 |     FOR(i,1,n)f[i]=max(f[i],g[i]);
      |             ^
dreaming.cpp:4:38: note: in definition of macro 'FOR'
    4 | #define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
      |                                      ^
dreaming.cpp:63:13: error: 'n' was not declared in this scope
   63 |     FOR(i,1,n)a[vst[i]]=min(a[vst[i]],f[i]);
      |             ^
dreaming.cpp:4:38: note: in definition of macro 'FOR'
    4 | #define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
      |                                      ^
dreaming.cpp:64:20: error: 'l' was not declared in this scope
   64 |     f[0]=calc(*vst,l,a);
      |                    ^
dreaming.cpp:65:31: error: 'n' was not declared in this scope
   65 |     return *max_element(f,f+1+n);
      |                               ^