Submission #347192

# Submission time Handle Problem Language Result Execution time Memory
347192 2021-01-12T09:59:28 Z Noran One-Way Streets (CEOI17_oneway) C++14
Compilation error
0 ms 0 KB
using namespace std;

#define pb push_back
#define F first
#define S second
#define debug(x) cerr<<#x<<" :"<<x<<"\n"
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define FAST ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
//#define int long long

typedef long long ll;
typedef long double ld;

const int maxn = 1e5 + 7;
const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const int mlog = 19;
const int SQ = 400;

int n, m;

int a[maxn], b[maxn];

int mark[maxn], low[maxn], h[maxn];
bool dfn[maxn];

vector<pii> adj[maxn];

int par[maxn][mlog];
int f[maxn];

int parID[maxn];
int res[maxn];

int cnt = 0;

int get(int v) { return (f[v] == v ? v : get(f[v])); }

void dfs(int v)
{
    mark[v] = low[v] = ++cnt;
    for(pii Ed : adj[v])
    {
        int u = Ed.F;
        int ind = Ed.S;

        if(!mark[u])
        {
            h[u] = h[v] + 1;
            par[u][0] = v;
            parID[u] = ind;
            dfs(u);

            low[v] = min(low[u], low[v]);

            if(low[u] > mark[v]) dfn[u] = 1;
        }
        else
        {
            if(par[u][0] == v) dfn[u] = 0;
            if(u != par[v][0]) low[v] = min(low[u], low[v]);
        }
    }
}

void prep()
{
    for(int j=1;j<mlog;j++)
        for(int i=1;i<=n;i++)
            par[i][j] = par[par[i][j-1]][j-1];
}

int lca(int u,int v)
{
    if(h[u] > h[v])
        swap(u, v);

    for(int i=mlog-1;i >= 0;i--)
        if(h[par[v][i]] >= h[u])
            v = par[v][i];

    if(u == v) return v;

    for(int i=mlog-1;i>=0;i--)
    {
        if(par[u][i] != par[v][i])
        {
            u = par[u][i];
            v = par[v][i];
        }
    }

    return par[v][0];
}

int main()
{
    FAST;

    cin >> n >> m;

    for(int i=1;i<=m;i++)
    {
        cin >> a[i] >> b[i];

        adj[a[i]].pb({b[i], i});
        adj[b[i]].pb({a[i], i});
    }

    for(int i=1;i<=n;i++) if(!mark[i]) dfs(i);

    prep();

    for(int i=1;i<=n;i++) f[i] = i;

    int p;
    cin >> p;

    while(p--)
    {
        int u, v;
        cin >> u >> v;

        int lpa = lca(u, v);

        u = get(u);
        while(h[u] > h[lpa])
        {
            if(dfn[u]) res[parID[u]] = -1;
            f[u] = par[u][0];
            u = get(u);
        }

        v = get(v);
        while(h[v] > h[lpa])
        {
            if(dfn[v]) res[parID[v]] = 1;
            f[v] = par[v][0];
            v = get(v);
        }
    }

    for(int i=1;i<=n;i++)
        if(dfn[i] && b[parID[i]] != i)
            res[parID[i]] *= -1;

    for(int i=1;i<=m;i++)
    {
        if(res[i] == 1) cout << "R";
        if(res[i] == -1) cout << "L";
        if(res[i] == 0) cout << "B";
    }

    return 0;
}

Compilation message

oneway.cpp:29:1: error: 'vector' does not name a type
   29 | vector<pii> adj[maxn];
      | ^~~~~~
oneway.cpp: In function 'void dfs(int)':
oneway.cpp:9:13: error: 'pair' was not declared in this scope
    9 | #define pii pair<int,int>
      |             ^~~~
oneway.cpp:44:9: note: in expansion of macro 'pii'
   44 |     for(pii Ed : adj[v])
      |         ^~~
oneway.cpp:1:1: note: 'std::pair' is defined in header '<utility>'; did you forget to '#include <utility>'?
  +++ |+#include <utility>
    1 | 
oneway.cpp:9:18: error: expected primary-expression before 'int'
    9 | #define pii pair<int,int>
      |                  ^~~
oneway.cpp:44:9: note: in expansion of macro 'pii'
   44 |     for(pii Ed : adj[v])
      |         ^~~
oneway.cpp:66:1: error: expected primary-expression before '}' token
   66 | }
      | ^
oneway.cpp:65:6: error: expected ';' before '}' token
   65 |     }
      |      ^
      |      ;
   66 | }
      | ~     
oneway.cpp:66:1: error: expected primary-expression before '}' token
   66 | }
      | ^
oneway.cpp:65:6: error: expected ')' before '}' token
   65 |     }
      |      ^
      |      )
   66 | }
      | ~     
oneway.cpp:44:8: note: to match this '('
   44 |     for(pii Ed : adj[v])
      |        ^
oneway.cpp:66:1: error: expected primary-expression before '}' token
   66 | }
      | ^
oneway.cpp: In function 'int lca(int, int)':
oneway.cpp:78:9: error: 'swap' was not declared in this scope
   78 |         swap(u, v);
      |         ^~~~
oneway.cpp: In function 'int main()':
oneway.cpp:10:14: error: 'ios_base' has not been declared
   10 | #define FAST ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
      |              ^~~~~~~~
oneway.cpp:100:5: note: in expansion of macro 'FAST'
  100 |     FAST;
      |     ^~~~
oneway.cpp:10:48: error: 'cin' was not declared in this scope
   10 | #define FAST ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
      |                                                ^~~
oneway.cpp:100:5: note: in expansion of macro 'FAST'
  100 |     FAST;
      |     ^~~~
oneway.cpp:1:1: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
  +++ |+#include <iostream>
    1 | 
oneway.cpp:10:59: error: 'cout' was not declared in this scope
   10 | #define FAST ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
      |                                                           ^~~~
oneway.cpp:100:5: note: in expansion of macro 'FAST'
  100 |     FAST;
      |     ^~~~
oneway.cpp:10:59: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
   10 | #define FAST ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
      |                                                           ^~~~
oneway.cpp:100:5: note: in expansion of macro 'FAST'
  100 |     FAST;
      |     ^~~~
oneway.cpp:108:9: error: 'adj' was not declared in this scope
  108 |         adj[a[i]].pb({b[i], i});
      |         ^~~