QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#392272 | #4686. Tours | OccDreamer | WA | 2ms | 14036kb | C++14 | 2.7kb | 2024-04-17 13:49:13 | 2024-04-17 13:49:14 |
Judging History
answer
//code by Emissary
#include<bits/stdc++.h>
#define vc vector
#define db double
#define fi first
#define se second
#define ll long long
#define mk make_pair
#define pb push_back
#define RI register int
#define PI pair<int,int>
#define ull unsigned long long
#define err cerr << " -_- " << endl
#define debug cerr << " ------------------- " << endl
#define input(x) freopen(#x".in","r",stdin)
#define output(x) freopen(#x".out","w",stdout)
#define NO puts("No")
#define YES puts("Yes")
//#define OccDreamer
//#define int long long
using namespace std;
namespace IO{
inline int read(){
int X=0, W=0; char ch=getchar();
while(!isdigit(ch)) W|=ch=='-', ch=getchar();
while(isdigit(ch)) X=(X<<1)+(X<<3)+(ch^48), ch=getchar();
return W?-X:X;
}
inline void write(int x){
if(x<0) x=-x, putchar('-');
if(x>9) write(x/10);
putchar(x%10+'0');
}
inline void sprint(int x){write(x), putchar(32);}
inline void eprint(int x){write(x), putchar(10);}
}using namespace IO;
const int MAXN = 1e5+5;
int n, m, tot, ss;
int fa[MAXN], siz[MAXN], id[MAXN], total[MAXN];
int head[MAXN], ne[MAXN<<1], to[MAXN<<1], cnt;
vc<int> G[MAXN];
vc<PI> T[MAXN];
PI F[MAXN];
mt19937_64 rnd(time(0));
ull val[MAXN], hsh[MAXN], oo[MAXN], oc[MAXN], tree[MAXN];
bool ins[MAXN], vis[MAXN];
inline int lowbit(int x){return x & -x;}
inline void Add(int x, ull v){while(x<=n) tree[x]+=v, x+=lowbit(x);}
inline ull Ask(int x){ull s=0; while(x) s^=tree[x], x^=lowbit(x); return s;}
inline void add(int x, int y){++cnt;to[cnt]=y;ne[cnt]=head[x];head[x]=cnt;}
inline void dfs(int x, int f){
ins[x]=1; fa[x]=f; siz[x]=1; id[x]=++tot; vis[x]=1;
for(int i=head[x];i;i=ne[i]){
if(to[i]==f) continue;
if(vis[to[i]]){
if(ins[to[i]]) F[++tot]=mk(x,to[i]), T[to[i]].pb(mk(x,tot));
continue;
}
G[x].pb(to[i]); dfs(to[i],x); siz[x]+=siz[to[i]];
}
ins[x]=0;
}
inline void calc(int x, int f){
for(auto i:T[x]){
Add(id[i.fi],val[i.se]);
oo[++ss]=Ask(id[i.fi]-1)^Ask(id[i.fi]+siz[i.fi]-1);
}
if(f) oo[++ss]=hsh[x];
for(auto i:G[x]) calc(i,x);
for(auto i:T[x]) Add(id[i.fi],val[i.se]);
}
signed main(){
n=read(), m=read();
for(int i=1;i<=m;++i){
int x, y;
x=read(), y=read();
add(x,y); add(y,x);
}
dfs(1,0);
for(int i=1;i<=tot;++i){
val[i]=rnd();
int u=F[i].fi, e=F[i].se;
while(u!=e) hsh[u]^=val[i], u=fa[u];
}
calc(1,0); sort(oo+1,oo+1+ss);
for(int i=1;i<=ss;++i) oc[i]=oo[i];
int len=ss; ss=unique(oo+1,oo+1+ss)-oo-1;
for(int i=1;i<=len;++i) total[lower_bound(oo+1,oo+1+ss,oc[i])-oo]++;
int g=0;
for(int i=1;i<=ss;++i) if(oo[i]) g=__gcd(g,total[i]);
for(int i=1;i<=g;++i) if(g%i==0) sprint(i);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 13908kb
input:
4 5 1 2 2 3 3 4 1 4 1 3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 2ms
memory: 11904kb
input:
6 6 1 2 2 3 1 3 1 4 2 5 3 6
output:
1 3
result:
ok 2 number(s): "1 3"
Test #3:
score: 0
Accepted
time: 0ms
memory: 13904kb
input:
4 5 1 2 3 4 2 3 1 4 1 3
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 2ms
memory: 14036kb
input:
6 6 1 2 2 3 1 4 2 5 1 3 3 6
output:
1 3
result:
ok 2 number(s): "1 3"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 13936kb
input:
9 10 1 2 2 3 3 4 4 5 5 6 6 7 7 8 1 8 4 9 6 9
output:
1
result:
wrong answer Answer contains longer sequence [length = 2], but output contains 1 elements