QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#181555#6634. Central Subsetucup-team134#WA 14ms8048kbC++144.1kb2023-09-16 20:40:482023-09-16 20:40:49

Judging History

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

  • [2023-09-16 20:40:49]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:8048kb
  • [2023-09-16 20:40:48]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<int D, typename T>struct vec : public vector<vec<D - 1, T>> {template<typename... Args>vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {}};
template<typename T>struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val) {}};
template<class T1,class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const deque<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
int ri(){int x;scanf("%i",&x);return x;}
void rd(int&x){scanf("%i",&x);}
void rd(long long&x){scanf("%lld",&x);}
void rd(double&x){scanf("%lf",&x);}
void rd(long double&x){scanf("%Lf",&x);}
void rd(string&x){cin>>x;}
void rd(char*x){scanf("%s",x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&p:x)rd(p);}
template<typename C,typename...T>void rd(C&a,T&...args){rd(a);rd(args...);}
//istream& operator>>(istream& is,__int128& a){string s;is>>s;a=0;int i=0;bool neg=false;if(s[0]=='-')neg=true,i++;for(;i<s.size();i++)a=a*10+s[i]-'0';if(neg)a*=-1;return is;}
//ostream& operator<<(ostream& os,__int128 a){bool neg=false;if(a<0)neg=true,a*=-1;ll high=(a/(__int128)1e18);ll low=(a-(__int128)1e18*high);string res;if(neg)res+='-';if(high>0){res+=to_string(high);string temp=to_string(low);res+=string(18-temp.size(),'0');res+=temp;}else res+=to_string(low);os<<res;return os;}

const int N=2e5+5;
vector<vector<int>> graf(N);
vector<int> s;
vector<bool> visited(N);
bool dfs(int tr,int dist,int x){
	bool stavio=0;
	if(dist>(2*x-1)){
		s.pb(tr);
		dist=0;
		stavio=1;
	}
	visited[tr]=1;
	for(auto p:graf[tr]){
		if(!visited[p]){
			bool d=dfs(p,dist+1,x);
			if(d){
				stavio=1;
			}
		}
	}
	if(dist>x&&!stavio){
		s.pb(tr);
		dist=0;
		stavio=1;
	}
	return stavio;
}
void test(){
	int n=ri(),m=ri();
	for(int i=0;i<n;i++){
		graf[i].clear();
	}
	for(int i=0;i<m;i++){
		int u=ri()-1,v=ri()-1;
		graf[u].pb(v);
		graf[v].pb(u);
	}
	int x=sqrt(n)+10;
	while((x-1)*(x-1)>=n){
		x--;
	}
	s.clear();
	for(int i=0;i<n;i++){
		visited[i]=0;
	}
	dfs(rng()%n,2*n+1,x);
	printf("%i\n",sz(s));
	for(auto p:s){
		printf("%i ",p+1);
	}
	printf("\n");
}
int main()
{
	int t=ri();
	while(t--){
		test();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 8048kb

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:

1
3 
2
6 3 

result:

ok correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 14ms
memory: 7960kb

input:

10000
15 14
13 12
5 4
9 8
11 12
15 14
10 9
14 13
2 3
2 1
6 5
10 11
3 4
7 6
8 7
6 5
2 1
2 4
4 6
2 3
3 5
10 9
8 3
9 4
5 6
5 10
3 2
5 4
2 7
1 2
4 3
2 1
2 1
2 1
2 1
9 8
9 8
5 4
1 2
6 5
3 4
3 2
7 8
7 6
2 1
1 2
14 13
3 10
5 6
2 9
11 4
2 3
2 1
8 7
13 6
5 4
5 12
6 7
4 3
7 14
16 15
2 3
2 1
6 10
6 9
6 4
9 11
...

output:

3
9 1 15 
1
1 
1
5 
1
2 
1
2 
2
1 7 
1
2 
4
7 10 9 1 
4
13 11 1 5 
1
1 
3
7 17 1 
2
7 1 
3
7 10 6 
4
17 6 1 9 
1
2 
3
2 10 15 
2
5 6 
1
1 
2
3 9 
1
17 
2
1 4 
2
5 8 
3
11 14 8 
1
8 
1
4 
2
11 3 
1
3 
5
15 11 10 1 12 
1
2 
1
1 
3
2 12 21 
3
10 13 9 
3
12 1 9 
4
1 13 14 16 
1
4 
2
2 6 
3
1 6 7 
3
6 8 ...

result:

wrong answer Integer 5 violates the range [1, 4] (test case 28)