QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#518002#6634. Central SubsetCleshmWA 3ms16264kbC++143.4kb2024-08-13 15:07:502024-08-13 15:07:50

Judging History

你现在查看的是最新测评结果

  • [2024-08-13 15:07:50]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:16264kb
  • [2024-08-13 15:07:50]
  • 提交

answer

#include "bits/stdc++.h"
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define OPEN freopen ("set.in", "r", stdin); freopen ("set.out", "w", stdout);
#define pc __builtin_popcount
#define db double
#define pii pair<int, int>
#define fi first
#define se second
#define F(i,x,y) for (int i = (x); i <= (y); ++i)
#define D(i,x,y) for (int i = (x); i >= (y); --i)

using namespace std;

const ll inf = 1ll * 1e18;
//const ll mod = 998244353ll;

const ll mod = 1ll * 1e9 + 7ll;

inline void Rd(int& x) {
	int f = 1;
	x = 0;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') f = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c - 48), c = getchar();
	x *= f;
}

inline void Wt(int x) {
	if (x < 10) {
		putchar(x + 48);
		return;
	}
	Wt(x / 10);
	putchar((x % 10) + 48);
}
int n, m;
struct Dsu {
	int f[310000];

	void Init() {
		F(i, 1, n) f[i] = i;
	}

	int Find (int x) {
		if (x == f[x]) return x;
		return f[x] = Find(f[x]);
	}

	void U (int x, int y) {
		int tx = Find(x), ty = Find(y);

		f[tx] = ty;
	}
} w;

struct Node {
	int dep, id;
	vector<int> v;

	bool operator <(const Node& p) const {
		return dep > p.dep;
	}
} t[310000];

struct Ds {
	int id, dis;
};

void Dfs(int now, int dp) {
	t[now].dep = dp;
//	if(now%20000==0)cerr<<now<<':'<<(double)clock() / CLOCKS_PER_SEC<<'\n';
	for (auto i : t[now].v) {
		if (! t[i].dep) {
			Dfs (i, dp + 1);
		}
	}
}

queue<Ds> q;
vector<int> ans;
int dis[310000];

int vis[310000];

int nid[310000];

int main() {
	//OPEN
	IOS
	cin >> n >> m;
	w.Init();
//	cerr<<(double)clock() / CLOCKS_PER_SEC<<'\n';
	F(i, 1, m) {
		int x, y;
		cin >> x >> y;
//		if(i%100000==0)cerr<<(double)clock() / CLOCKS_PER_SEC<<'\n';
		int tx = w.Find(x), ty = w.Find(y);
//		cerr <<x<<' '<<y<<' '<<tx<<' '<<ty<<'\n';
		if (tx != ty) {
			w.U(x, y);
			t[x].v.push_back(y);
			t[y].v.push_back(x);
		}
	}
//	cerr<<(double)clock() / CLOCKS_PER_SEC<<'\n';

//	F(i, 1, n) {
//		cerr<<i<<':';
//		for (auto j : t[i].v) cerr << j << ' ';
//		cerr << '\n';
//	}
	Dfs(1, 1);
//	cerr<<(double)clock() / CLOCKS_PER_SEC<<'\n';
	F(i, 1, n) t[i].id = i;
	
//	F(i, 1, n) cerr << t[i].dep << '\n';
	sort (t + 1, t + n + 1);
	F(i, 1, n) nid[t[i].id] = i;
	int k = 0;
	for(int i = 1; ; ++ i) {
		if (i * i >= n) {
			k = i;
			break;
		}
	}
	int nxt = -1;
	F(i, 1, n) dis[i] = 0x3f3f3f3f;
//	cerr<<(double)clock() / CLOCKS_PER_SEC<<'\n';
	F(i, 1, n) {
//		cerr<<nxt<<'\n';
//		F(j,1,n)cerr<<dis[j]<<' ';
//		cerr<<'\n';
		if (nxt != -1 && t[i].dep == nxt) {
			Ds u, to;
//			cerr<<"w"<<t[i].id <<'\n';
			u.dis = 0, u.id = t[i].id;
			q.push(u);
			F(j, 1, n) vis[j] = 0;
			while (! q.empty()) {
				u = q.front();
				q.pop();
//				cerr<<u.id<<':';
				for (auto j : t[nid[u.id]].v) {
//					cerr<<j<<' ';
					to.id = j, to.dis = u.dis + 1;
					if (! vis[to.id]) {
						vis[to.id] = 1;
						dis[to.id] = min(dis[to.id], to.dis);
						q.push(to);
					}
				}
//				cerr<<'\n';
			}
			ans.push_back(t[i].id);
			nxt = -1;
		}
		if (dis[i] > k && nxt == -1) {
//			cerr<<t[i].dep<<' '<<k<<'\n';
			nxt = max(t[i].dep - k, 1);
		}
//		cerr<<nxt<<'\n';
//		F(j,1,n)cerr<<dis[j]<<' ';
//		cerr<<'\n';
	}
//	F(i, 1, n) cerr <<dis[i] << ' ';
	cout << ans.size() << '\n';
	for (auto i : ans) cout << i << ' ';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 16264kb

input:

2
4 3
1 2
2 3
3 4
6 7
1 2
2 3
3 1
1 4
4 5
5 6
6 4

output:

0

result:

wrong answer Integer 0 violates the range [1, 2] (test case 1)