Submission #585283

# Submission time Handle Problem Language Result Execution time Memory
585283 2022-06-28T14:20:54 Z krit3379 One-Way Streets (CEOI17_oneway) C++17
100 / 100
176 ms 22196 KB
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define N 100005

struct A{
    int a,flag,id;
};

int dp[N];
vector<A> g[N];
bitset<N> vis,cycle,both,res;
map<pair<int,int>,int> mp;
pair<int,int> edge[N];

void dfs(int s,int f){
    vis[s]=true;
    for(auto [x,flag,id]:g[s]){
        if(x==f)continue;
        if(vis[x]&&!cycle[id])cycle[id]=true,dp[s]++,dp[x]--;
        else if(!vis[x])dfs(x,s);
    }
}

void sol1(int s,int f){
    vis[s]=true;
    for(auto [x,flag,id]:g[s]){
        if(x==f||vis[x])continue;
        sol1(x,s);
        if(dp[x])cycle[id]=true;
        dp[s]+=dp[x];
    }
}

void sol2(int s,int f){
    vis[s]=true;
    for(auto [x,flag,id]:g[s]){
        if(x==f||vis[x])continue;
        sol2(x,s);
        if(dp[x]){
            bool f=dp[x]>0?true:false;
            res[id]=f^flag;
        }
        else both[id]=true;
        dp[s]+=dp[x];
    }
}

int main(){
    int n,m,p,i,a,b;
    scanf("%d %d",&n,&m);
    for(i=1;i<=m;i++){
        scanf("%d %d",&a,&b);
        if(!mp.count(minmax(a,b))){
            g[a].push_back({b,0,i});
            g[b].push_back({a,1,i});
        }
        mp[minmax(a,b)]++;
        edge[i]={a,b};
    }
    for(i=1;i<=n;i++)if(!vis[i])dfs(i,0);
    vis=0;
    for(i=1;i<=n;i++)if(!vis[i])sol1(i,0);
    vis=0;
    for(i=1;i<=n;i++)dp[i]=0;
    scanf("%d",&p);
    while(p--){
        scanf("%d %d",&a,&b);
        dp[a]++,dp[b]--;
    }
    vis=0;
    for(i=1;i<=n;i++)if(!vis[i])sol2(i,0);
    for(i=1;i<=m;i++){
        if(cycle[i]||both[i]||mp[minmax(edge[i].first,edge[i].second)]>1)printf("B");
        else if(res[i])printf("L");
        else printf("R");
    }
    return 0;
}

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
oneway.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         scanf("%d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~
oneway.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |     scanf("%d",&p);
      |     ~~~~~^~~~~~~~~
oneway.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         scanf("%d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2672 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2804 KB Output is correct
9 Correct 2 ms 2772 KB Output is correct
10 Correct 2 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2672 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2804 KB Output is correct
9 Correct 2 ms 2772 KB Output is correct
10 Correct 2 ms 2680 KB Output is correct
11 Correct 100 ms 16248 KB Output is correct
12 Correct 110 ms 16924 KB Output is correct
13 Correct 123 ms 18084 KB Output is correct
14 Correct 139 ms 18380 KB Output is correct
15 Correct 149 ms 18068 KB Output is correct
16 Correct 128 ms 15616 KB Output is correct
17 Correct 135 ms 17288 KB Output is correct
18 Correct 137 ms 15572 KB Output is correct
19 Correct 129 ms 18752 KB Output is correct
20 Correct 116 ms 16240 KB Output is correct
21 Correct 100 ms 15460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2672 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2804 KB Output is correct
9 Correct 2 ms 2772 KB Output is correct
10 Correct 2 ms 2680 KB Output is correct
11 Correct 100 ms 16248 KB Output is correct
12 Correct 110 ms 16924 KB Output is correct
13 Correct 123 ms 18084 KB Output is correct
14 Correct 139 ms 18380 KB Output is correct
15 Correct 149 ms 18068 KB Output is correct
16 Correct 128 ms 15616 KB Output is correct
17 Correct 135 ms 17288 KB Output is correct
18 Correct 137 ms 15572 KB Output is correct
19 Correct 129 ms 18752 KB Output is correct
20 Correct 116 ms 16240 KB Output is correct
21 Correct 100 ms 15460 KB Output is correct
22 Correct 171 ms 18556 KB Output is correct
23 Correct 172 ms 16572 KB Output is correct
24 Correct 176 ms 16724 KB Output is correct
25 Correct 163 ms 22196 KB Output is correct
26 Correct 163 ms 18064 KB Output is correct
27 Correct 160 ms 16644 KB Output is correct
28 Correct 66 ms 5064 KB Output is correct
29 Correct 126 ms 16972 KB Output is correct
30 Correct 126 ms 16960 KB Output is correct
31 Correct 134 ms 17428 KB Output is correct
32 Correct 119 ms 17052 KB Output is correct