QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#876703#8544. Colorful Graph 2JEdwardWA 1ms3584kbC++202.2kb2025-01-31 11:19:442025-01-31 11:19:46

Judging History

This is the latest submission verdict.

  • [2025-01-31 11:19:46]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3584kb
  • [2025-01-31 11:19:44]
  • Submitted

answer

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define int long long
#define endl '\n'
#define lowbit(x) (x & -x)
#define all(s) s.begin(), s.end()
#define pii pair<int,int>
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define here system("pause")
using namespace std;
template <class T>
inline void read(T &x){
	x = 0;
	char c = getchar();
	bool f = 0;
	for (; !isdigit(c); c = getchar()) f ^= (c == '-');
	for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
	x = f ? -x : x;
}
template <class T>
inline void write(T x){
	if (x < 0) putchar('-'), x = -x;
	if (x < 10) putchar(x + 48);
	else write(x / 10), putchar(x % 10 + 48);
}
template<typename T> void chkmin(T& lhs, const T& rhs) { lhs = lhs > rhs ? rhs : lhs; }
template<typename T> void chkmax(T& lhs, const T& rhs) { lhs = lhs < rhs ? rhs : lhs; }

const int N = 2e3 + 4;
const int mod = 998244353;
const int INF = 8e18 + 9;
const double eps = 1e-9;
const double Pi = acos(-1);
inline int pow(int a, int b, int p){ int res = 1%p; while(b){ if(b&1) res=res*a%p; a=a*a%p, b>>=1;} return res;}
inline int inv(int a, int p){ return pow(a,p-2,p)%p;}
mt19937 rnd(chrono::duration_cast<chrono::nanoseconds>(chrono::system_clock::now().time_since_epoch()).count());
int randint(int L, int R) {
	uniform_int_distribution<int> dist(L, R);
	return dist(rnd);
}
inline void sol() {
	int n, k;
	cin >> n >> k;
	vector<vector<int>> adj(n);
	vector<int> dis(n, INF);
	vector<bool> vis(n, false);
	for(int i = 0; i < n; i++) {
		int u = i, v = i + 1 >= n ? i + 1 - n : i + 1;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for(int i = 0; i < k; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	auto dfs = [&](auto&& dfs, int u, int fa) -> void {
		for(auto v : adj[u]) {
			if(v == fa || vis[v]) continue;
			if(dis[u] + 1 < dis[v]) {
				dis[v] = dis[u] + 1;
				vis[v] = true;
				dfs(dfs, v, u);
			}
		}
	};
	dis[0] = 0;
	vis[0] = true;
	dfs(dfs, 0, -1);
	for(int i = 0; i < n; i++) {
		cout << (dis[i] & 1 ? 'R' : 'B');
	}
	cout << endl;
}

signed main(){
	IOS;
	int tc = 1;
	cin >> tc;
	cout << fixed << setprecision(10);
	while(tc--){
		sol();
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3584kb

input:

3
3 0
4 1
1 3
6 3
0 2
2 4
4 0

output:

BRB
BRBR
BRBRBR

result:

wrong answer cycle detected (test case 3)