Submission #1276588

#TimeUsernameProblemLanguageResultExecution timeMemory
1276588avohadoDreaming (IOI13_dreaming)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define mod 1000000007
#define maxn 200005
#define f first
#define s second
#define ll long long
#define pb(x) push_back(x)
vector<pair<int, int>> g[maxn];
bool a[maxn];
pair<ll, int> b[maxn][2];
int c[maxn];
std::queue<pair<int, ll>> q;
void dfs(int u, int p){
    if(g[u].size()<=1){
        q.push({u, 0}});
    }
    for(auto i:g[u]){
        if(i.f!=p){
            dfs(i.f, u);
        }
    }
}
void dfs2(int u, int p){
    for(auto i:g[u]){
        if(i.f!=p){
            for(int j=0; j<2; j++){
                if(b[u][j].s!=i.f){
                    if(b[u][j].f+i.s>b[i.f][0].f){
                        b[i.f][1].f=b[i.f][0].f;
                        b[i.f][0].f=b[u][j].f+i.s;
                    }else if(b[u][j].f+i.s>b[i.f][1].f){
                        b[i.f][1].f=b[u][j].f+i.s;
                    }
                }
            }
            dfs2(i.f, u);
        }
    }
}
void dfs3(int u, int p){
    ll mn=INT64_MAX;
    for(auto i:g[u]){
        if(i.f!=p)
        mn=min(mn, dfs3(i.s,u));
    }
    return min(mn, b[u][0].f)
}
int travelTime(int N,int M,int L,int A[],int B[],int T[]){
    for(int i=0; i<M; i++){
        g[A[i]].push_back({B[i], T[i]});
        g[B[i]].push_back({A[i], T[i]});
    }
    vector<long long> v;
    for(int i=0; i<M; i++){
        c[i]=g[i].size();
    }
    for(int i=0; i<M; i++){
        if(!a[i]){
            k=INT64_MAX;
            dfs(i, i);
            while(q.size()){
                int u=q.front().f; ll sum=q.front().s;
                q.pop();
                a[u]=1;
                if(c[u]==0){
                    break;
                }
                for(auto v:g[u]){
                    if(!a[v.f]){
                        if(v.s+sum>b[v.f][0].f){
                            b[v.f][1]=b[v.f][0];
                            b[v.f][0]={v.s+sum,u};
                        }else if(b[v.f][1].f<v.s+sum){
                            b[v.f][1]={v.s+sum,u};
                        }
                        c[v.f]--;
                        if(c[v.f]==1){
                            q.push({v.f,b[v.f][0].f});
                        }
                    }
                }
            }
            dfs2(q.front().f, q.front().f);
            v.pb(dfs3(i, i));
        }
    }
    sort(v.begin(), v.end(), greater<>());
    if(v.size()>2){
        return v[0]+v[1]+L;
    }else{
        return max(v[0]+v[1]+L, v[1]+v[2]+L*2);
    }
}

Compilation message (stderr)

dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:17:22: error: expected ')' before '}' token
   17 |         q.push({u, 0}});
      |               ~      ^
      |                      )
dreaming.cpp:17:23: error: expected primary-expression before ')' token
   17 |         q.push({u, 0}});
      |                       ^
dreaming.cpp: At global scope:
dreaming.cpp:19:5: error: expected unqualified-id before 'for'
   19 |     for(auto i:g[u]){
      |     ^~~
dreaming.cpp:24:1: error: expected declaration before '}' token
   24 | }
      | ^
dreaming.cpp: In function 'void dfs3(int, int)':
dreaming.cpp:46:24: error: invalid use of void expression
   46 |         mn=min(mn, dfs3(i.s,u));
      |                    ~~~~^~~~~~~
dreaming.cpp:48:15: error: return-statement with a value, in function returning 'void' [-fpermissive]
   48 |     return min(mn, b[u][0].f)
      |            ~~~^~~~~~~~~~~~~~~
dreaming.cpp:48:30: error: expected ';' before '}' token
   48 |     return min(mn, b[u][0].f)
      |                              ^
      |                              ;
   49 | }
      | ~                             
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:61:13: error: 'k' was not declared in this scope
   61 |             k=INT64_MAX;
      |             ^
dreaming.cpp:86:22: error: invalid use of void expression
   86 |             v.pb(dfs3(i, i));
      |                  ~~~~^~~~~~
dreaming.cpp:9:25: note: in definition of macro 'pb'
    9 | #define pb(x) push_back(x)
      |                         ^