QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#864950 | #1351. Koosaga's Problem | gyydp123_LIM | WA | 2ms | 6108kb | C++20 | 1.8kb | 2025-01-21 11:47:10 | 2025-01-21 11:47:11 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=(j);i<=(k);++i)
#define ForDown(i,j,k) for(int i=(j);i>=(k);--i)
#define Debug(fmt, args...) fprintf(stderr,"(func %s, line #%d): " fmt,__func__,__LINE__,##args),fflush(stderr)
#define debug(fmt, args...) fprintf(stderr,fmt,##args),fflush(stderr)
#define within :
#define LJY main
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2.5e5+5;
// mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
mt19937_64 rnd(1);
inline int read(){
char ch=getchar();int x=0,f=1;
while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')
x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return x*f;
}
int n,m;vector<pair<int,int> >G[N];
ull val[N],s[N];bool vis[N];
void dfs1(int u,int fa){
vis[u]=1;
for(auto [v,id] within G[u]) if(id!=fa){
if(!vis[v]) dfs1(v,id);
else if(u<v) val[id]=rnd(),s[u]^=val[id],s[v]^=val[id];
}
}
void dfs2(int u,int fa){
vis[u]=1;
for(auto [v,id] within G[u]) if(id!=fa&&!vis[v])
dfs2(v,id),val[id]=s[v],s[u]^=s[v];
}
signed LJY(){
n=read();m=read();
For(i,1,m){
int u=read(),v=read();
G[u].emplace_back(v,i);
G[v].emplace_back(u,i);
}For(i,1,n) if(!vis[i]) dfs1(i,0);
memset(vis,0,sizeof(vis));
For(i,1,n) if(!vis[i]) dfs2(i,0);
sort(val+1,val+1+m);
ull sum=0;For(i,1,m) sum^=val[i];
// For(i,1,m) debug("%llu ",val[i]);debug("\n");
// debug("%llu\n",sum);
if(sum==0){puts("1");return 0;}
ll cnt=0;For(i,1,m) cnt+=(val[i]==cnt);
if(cnt){printf("%lld\n",cnt);return 0;}
For(i,1,m){
int l=lower_bound(val+1,val+1+m,sum^val[i])-val;
int r=upper_bound(val+1,val+1+m,sum^val[i])-val;
// Debug("%llu %d %d\n",sum^val[i],l,r);
cnt+=r-l;
}printf("%lld\n",cnt/2);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5964kb
input:
3 2 1 2 2 3
output:
1
result:
ok answer is '1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 6104kb
input:
4 6 1 2 1 3 1 4 2 3 2 4 3 4
output:
3
result:
ok answer is '3'
Test #3:
score: 0
Accepted
time: 2ms
memory: 6104kb
input:
5 9 1 2 1 3 1 4 2 3 2 4 2 5 3 4 3 5 4 5
output:
0
result:
ok answer is '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 6108kb
input:
12 16 1 2 2 3 3 4 4 1 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 5 1 5 2 7 3 9 4 11
output:
2
result:
ok answer is '2'
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 6108kb
input:
3 3 1 2 2 3 3 1
output:
0
result:
wrong answer expected '3', found '0'