답안 #954469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954469 2024-03-28T02:46:16 Z koukirocks One-Way Streets (CEOI17_oneway) C++17
0 / 100
1 ms 4700 KB
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("popcnt")
 
namespace{using namespace std;}
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll MAX=1e5+10,P=1e9+7;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
const ldb eps=1e-6;

int n,m,pr;
vector<pii> G[MAX];
vector<pii> eg;
int dfn[MAX];
int tme=1;
int low[MAX];
int fa[MAX];
int st[MAX],ed[MAX];
bool vis[MAX];
vector<int> l,r;

void dfsid(int v,int p,int pid) {
	fa[v]=pid;
	dfn[v]=tme++;
	for (auto [i,id]:G[v]) {
		if (i==p) {
			p=-1;
			continue;
		}
		if (dfn[i]!=-1) continue;
		if (vis[i]) continue;
		dfsid(i,v,id);
		st[v]+=st[i];
		ed[v]+=ed[i];
	}
	vis[v]=true;
}

void dfslow(int v,int p) {
//	cout<<v<<" "<<p<<" vp\n";
	low[v]=v;
	for (auto [i,id]:G[v]) {
		if (i==p) {
			p=-1;
			continue;
		}
		if (dfn[i]<dfn[v]) {
//			cout<<v<<" "<<i<<" vi\n";
			if (dfn[i]<dfn[low[v]]) low[v]=i;
			continue;
		}
		if (vis[i]) continue;
		dfslow(i,v);
		if (dfn[low[i]]<dfn[low[v]]) low[v]=low[i];
	}
	vis[v]=true;
}

void dfsans(int v,int p) {
	if (low[v]==v and v!=1) {
//		cout<<v<<" bg\n";
		if (st[v]>ed[v]) {
			auto [a,b]=eg[fa[v]];
			if (v==a) r.push_back(fa[v]);
			else l.push_back(fa[v]);
		}
		if (st[v]<ed[v]) {
			auto [a,b]=eg[fa[v]];
			if (v==b) r.push_back(fa[v]);
			else l.push_back(fa[v]);
		}
	}
	for (auto [i,id]:G[v]) {
		if (i==p) {
			p=-1;
			continue;
		}
		if (dfn[i]<dfn[v]) continue;
		if (vis[i]) continue;
		dfsans(i,v);
	}
	vis[v]=true;
}

int main() {
	speed;
	cin>>n>>m;
	eg.emplace_back(0,0);
	for (int i=1;i<=m;i++) {
		int a,b;
		cin>>a>>b;
		G[a].emplace_back(b,i);
		G[b].emplace_back(a,i);
		eg.emplace_back(a,b);
	}
	memset(st,0,sizeof(st));
	memset(ed,0,sizeof(ed));
	cin>>pr;
	for (int i=0;i<pr;i++) {
		int a,b;
		cin>>a>>b;
		st[a]++;
		ed[b]++;
	}
	memset(dfn,-1,sizeof(dfn));
	memset(vis,0,sizeof(vis));
	dfsid(1,0,0);
	memset(vis,0,sizeof(vis));
	dfslow(1,0);
	memset(vis,0,sizeof(vis));
	dfsans(1,0);
//	for (int i=1;i<=n;i++) cout<<dfn[i]<<" ";
//	cout<<" dfn\n";
//	for (int i=1;i<=n;i++) cout<<low[i]<<" ";
//	cout<<" low\n";
//	for (int i:l) cout<<i<<" ";
//	cout<<" l\n";
//	for (int i:r) cout<<i<<" ";
//	cout<<" r\n";
	vector<pair<int,char> > ans;
	for (int i:l) ans.emplace_back(i,'L');
	for (int i:r) ans.emplace_back(i,'R');
	int id=0;
	sort(all(ans));
	for (int i=1;i<=m;i++) {
		if (id<ans.size() and ans[id].F==i) {
			cout<<ans[id].S;
			id++;
		} else cout<<"B";
	}
	return 0;
}

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:136:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  136 |   if (id<ans.size() and ans[id].F==i) {
      |       ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4700 KB Output isn't correct
2 Halted 0 ms 0 KB -