답안 #1027227

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027227 2024-07-19T02:17:07 Z ojnewbie111 One-Way Streets (CEOI17_oneway) C++14
0 / 100
1 ms 3928 KB
#include<bits/stdc++.h>
#define pi pair<int,int>
#define fi first
#define se second
using namespace std;
const int N=1e5+5;
int n,m,p;
struct node{
    int to,num,direct;
};
vector<node>g[N];
vector<pi>edge;
bool vis[N];
int num[N],low[N],tdfs=0;
bool bridge[N],joint[N];
void dfs(int u,int p)
{
    low[u]=num[u]=++tdfs;
    vis[u]=1;
    for (node &e:g[u]) {
        int v=e.to,pos=e.num;
        if (v==p) continue;
        if (!vis[v]) {
            dfs(v,u);
            low[u]=min(low[u],low[v]);
            if (low[v]==num[v]) bridge[pos]=1;
        }
        else low[u]=min(low[u],num[v]);
    }
}
int ans[N];
vector<pi>require;
void dfs2(int u,int p,int stop)
{
    vis[u]=1;
    if (u==stop) return;
    for (node &e:g[u]) {
        int v=e.to,pos=e.num;
        if (vis[v]) continue;
        if (bridge[pos] && !ans[pos]) {
            if (e.direct) ans[pos]=2; else ans[pos]=1;
        }
        dfs2(v,u,stop);
    }
}
int main()
{
    cin>>n>>m;
    for (int i=1;i<=m;i++) {int a,b; cin>>a>>b; edge.push_back({a,b}); g[a].push_back({b,i,0}); g[b].push_back({a,i,1});}
    cin>>p;
    for (int i=1;i<=p;i++) {int x,y; cin>>x>>y; require.push_back({x,y});}
    for (int i=1;i<=n;i++) if (!vis[i]) dfs(i,i);
    for (int i=1;i<=p;i++) {
        fill_n(vis,n+1,0);
        dfs2(require[i-1].fi,require[i-1].fi,require[i-1].se);
    }
    for (int i=1;i<=m;i++) if (ans[i]==0) cout<<"B"; else if (ans[i]==1) cout<<"R"; else cout<<"L";
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3928 KB Output isn't correct
2 Halted 0 ms 0 KB -