QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#185906 | #5670. Group Guests | 275307894a | WA | 480ms | 409876kb | C++14 | 2.9kb | 2023-09-22 19:44:11 | 2023-09-22 19:44:12 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=4e6+5,M=N*20+5,K=600+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(263082);
int m,n,X[N],Y[N],In[N];vector<int> S[N],G[N];
int dep[N];
int dp[N],flag;
vector<int> pot;
int sum;
void dfs1(int x,int La){
pot.emplace_back(x);sum++;
dp[x]=(La>0);dep[x]=dep[La]+1;
for(int i:S[x]) if(!dep[i]){
dfs1(i,x);dp[x]+=dp[i];sum--;
}else if(dep[x]<dep[i]) dp[x]++,sum--;
if(dp[x]>=3) flag=1;dp[x]&=1;
}
int dfn[N],low[N],dh,st[N],sh,Ct,fa[N],Si[N];vector<int> P[N];
void con(int x,int y){P[x].emplace_back(y);P[y].emplace_back(x);}
void dfs2(int x,int La){
dfn[x]=low[x]=++dh;st[++sh]=x;
for(int i:S[x]) if(i^La){
if(dfn[i]) {low[x]=min(low[x],dfn[i]);continue;}dfs2(i,x);low[x]=min(low[x],low[i]);
if(low[i]>=dfn[x]){con(++Ct,x);/*cerr<<"Pt "<<Ct<<'\n'<<x<<' ';*/while(st[sh+1]^i) /*cerr<<st[sh]<<' ',*/con(Ct,st[sh--]);/*cerr<<'\n';*/}
}
}
void dfs3(int x,int La){fa[x]=La;for(int i:P[x]) if(i^La) dfs3(i,x);}
void dfs4(int x,int La){for(int i:P[x]) if(i^La) dfs4(i,x),Si[x]+=Si[i];}
int g[N],gs[N];
int check(int x,int y,int z){
cerr<<x<<' '<<y<<' '<<z<<'\n';
int cir=fa[x];if(fa[y]==fa[z]) cir=fa[y];
cerr<<cir<<'\n';
auto find=[&cir](int x){
if(fa[x]==cir){
if(g[x]==2&&Si[x]&1) return 0;
} else{
if(g[cir]==2&&!(Si[cir]&1)) return 0;
}
return 1;
};
cerr<<find(z)<<'\n';
return find(x)&&find(y)&&find(z);
}
int calc(){
for(int i:pot){
for(int j:G[i]) gs[j]++;
for(int j:G[i]) for(int h:G[j]) if(gs[h]&&check(i,j,h)) return 1;
for(int j:G[i]) gs[j]=0;
}
return 0;
}
void Solve(){
int i,j;scanf("%d%d",&m,&n);
for(i=1;i<=m;i++) scanf("%d%d",&X[i],&Y[i]),In[X[i]]++,In[Y[i]]++;
for(i=1;i<=m;i++) S[X[i]].emplace_back(Y[i]),S[Y[i]].emplace_back(X[i]);
for(i=1;i<=m;i++){
if(In[X[i]]>In[Y[i]]) swap(X[i],Y[i]);
G[X[i]].emplace_back(Y[i]);
}
int ans1=0,ans2=0;Ct=n;
for(i=1;i<=n;i++) if(!dep[i]){
pot.clear();flag=sum=0;dfs1(i,0);if(!dp[i]) continue;
sh=0;dfs2(i,0);dfs3(i,0);
for(int j:pot) for(int h:S[j]) {
if(fa[h]==fa[j]||fa[fa[j]]==h) g[j]++,dfn[j]<dfn[h]&&(Si[fa[j]]++);else g[fa[h]]++,dfn[j]<dfn[h]&&(Si[fa[h]]++);
}
dfs4(i,0);//if(i%1000==0) cerr<<pot.size()<<' '<<Ct<<' '<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
if(calc()) continue;
if(!flag&&(sum>=0)) ans1++;
else ans2++;
}
printf("%d %d\n",ans1,ans2);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
详细
Test #1:
score: 100
Accepted
time: 35ms
memory: 300920kb
input:
2 4 1 2 3 4
output:
2 0
result:
ok single line: '2 0'
Test #2:
score: 0
Accepted
time: 39ms
memory: 294828kb
input:
2 3 1 2 3 1
output:
0 0
result:
ok single line: '0 0'
Test #3:
score: 0
Accepted
time: 32ms
memory: 305076kb
input:
5 5 1 2 2 3 2 4 5 2 5 4
output:
0 0
result:
ok single line: '0 0'
Test #4:
score: 0
Accepted
time: 480ms
memory: 401120kb
input:
999990 666660 1 2 1 5 1 7 1 8 1 9 1 10 2 4 2 6 2 9 2 10 3 4 4 8 5 8 6 7 6 10 11 13 11 15 11 20 12 17 12 19 13 16 13 19 14 16 14 19 15 17 15 18 16 17 16 19 17 18 17 20 21 26 21 27 21 29 22 26 22 27 22 29 23 26 23 30 24 26 24 28 25 27 25 30 26 27 26 29 28 29 31 33 31 40 32 35 33 35 33 37 33 38 33 39 3...
output:
383 523
result:
ok single line: '383 523'
Test #5:
score: 0
Accepted
time: 404ms
memory: 401764kb
input:
999990 666660 1 2 1 3 1 5 1 8 2 4 2 7 3 8 3 9 3 10 4 5 4 10 5 9 6 7 6 9 9 10 11 12 11 14 11 19 11 20 12 16 13 17 13 19 14 15 14 16 15 16 15 18 16 18 16 19 17 20 18 20 21 24 21 26 21 28 22 23 23 24 23 27 23 28 24 25 24 27 25 26 25 27 25 30 26 29 27 29 27 30 31 32 31 36 31 37 32 37 33 34 33 35 33 39 3...
output:
349 522
result:
ok single line: '349 522'
Test #6:
score: 0
Accepted
time: 27ms
memory: 294768kb
input:
4 4 1 2 2 4 2 3 3 4
output:
0 0
result:
ok single line: '0 0'
Test #7:
score: 0
Accepted
time: 452ms
memory: 399796kb
input:
999991 647053 1 2 1 4 1 7 1 8 1 10 2 4 2 9 3 8 3 9 3 11 4 6 6 10 7 9 7 11 8 9 9 10 10 11 12 13 12 15 12 21 13 16 13 19 13 22 14 17 14 19 14 20 15 19 15 22 16 20 17 18 17 19 18 20 19 22 20 21 23 25 23 27 23 28 23 30 24 25 24 31 24 32 25 30 25 31 26 32 26 33 27 30 28 32 29 31 29 32 29 33 30 31 34 37 3...
output:
375 322
result:
ok single line: '375 322'
Test #8:
score: 0
Accepted
time: 427ms
memory: 404464kb
input:
999991 647053 1 8 2 7 2 9 2 11 3 6 4 5 5 7 5 8 5 9 5 10 5 11 6 8 6 10 8 9 8 10 8 11 10 11 12 13 12 16 12 22 13 14 13 15 13 16 15 18 15 20 15 22 16 19 16 20 16 21 17 18 17 20 19 22 20 22 21 22 23 24 23 26 23 28 23 33 24 25 24 30 25 26 25 29 25 33 26 32 26 33 28 29 28 31 28 33 29 33 31 33 32 33 34 36 ...
output:
366 307
result:
ok single line: '366 307'
Test #9:
score: 0
Accepted
time: 31ms
memory: 303020kb
input:
5 5 1 2 2 4 2 3 5 4 3 4
output:
0 1
result:
ok single line: '0 1'
Test #10:
score: 0
Accepted
time: 423ms
memory: 409876kb
input:
999991 705876 1 5 1 9 2 5 2 7 2 8 3 4 5 6 6 7 6 9 6 10 6 11 6 12 7 9 7 11 8 10 9 10 11 12 13 14 13 15 13 16 13 18 13 19 14 17 15 19 15 21 16 21 17 19 18 24 19 20 20 21 21 22 21 23 22 23 23 24 25 28 25 31 25 34 26 31 27 28 27 32 28 29 28 33 28 36 29 32 29 33 29 36 30 35 31 34 31 35 32 34 32 35 37 45 ...
output:
1032 1376
result:
ok single line: '1032 1376'
Test #11:
score: 0
Accepted
time: 470ms
memory: 408792kb
input:
999991 705876 1 7 2 10 2 11 2 12 3 7 3 9 4 5 4 8 4 9 5 7 5 9 6 7 6 9 6 11 7 11 9 10 11 12 13 16 13 17 13 24 14 16 14 24 15 17 15 20 15 24 16 17 16 19 17 20 17 22 17 24 18 20 19 23 20 22 20 23 25 26 25 28 25 35 26 31 27 33 27 35 28 32 29 33 29 35 29 36 30 33 30 34 32 33 32 35 33 35 33 36 34 35 37 38 ...
output:
990 1439
result:
ok single line: '990 1439'
Test #12:
score: 0
Accepted
time: 34ms
memory: 298888kb
input:
6 6 1 4 3 2 4 3 4 6 4 5 4 2
output:
0 0
result:
ok single line: '0 0'
Test #13:
score: 0
Accepted
time: 39ms
memory: 305092kb
input:
7 7 1 6 6 7 6 2 2 5 2 3 2 4 3 4
output:
0 0
result:
ok single line: '0 0'
Test #14:
score: 0
Accepted
time: 44ms
memory: 298940kb
input:
8 8 1 2 2 7 2 8 7 8 5 2 2 3 2 4 5 6
output:
0 0
result:
ok single line: '0 0'
Test #15:
score: 0
Accepted
time: 27ms
memory: 298960kb
input:
12 8 1 2 1 3 2 3 3 4 3 5 4 5 6 5 6 7 5 7 2 7 7 8 2 8
output:
0 0
result:
ok single line: '0 0'
Test #16:
score: 0
Accepted
time: 40ms
memory: 305064kb
input:
5 4 1 2 1 3 2 3 2 4 3 4
output:
0 0
result:
ok single line: '0 0'
Test #17:
score: 0
Accepted
time: 23ms
memory: 298864kb
input:
6 7 1 2 2 7 2 3 3 4 4 5 5 6
output:
0 0
result:
ok single line: '0 0'
Test #18:
score: 0
Accepted
time: 39ms
memory: 302988kb
input:
7 8 1 4 4 5 6 7 6 8 2 4 2 3 6 3
output:
0 1
result:
ok single line: '0 1'
Test #19:
score: 0
Accepted
time: 28ms
memory: 305008kb
input:
7 8 1 2 1 3 1 4 5 6 5 7 5 8 1 5
output:
0 1
result:
ok single line: '0 1'
Test #20:
score: 0
Accepted
time: 27ms
memory: 298912kb
input:
4 4 1 3 1 4 2 4 2 3
output:
0 0
result:
ok single line: '0 0'
Test #21:
score: 0
Accepted
time: 31ms
memory: 305032kb
input:
5 5 1 2 1 5 2 4 4 3 3 5
output:
1 0
result:
ok single line: '1 0'
Test #22:
score: 0
Accepted
time: 40ms
memory: 305060kb
input:
9 12 1 2 1 3 4 5 5 6 7 9 8 9 10 11 10 12 11 12
output:
0 0
result:
ok single line: '0 0'
Test #23:
score: 0
Accepted
time: 27ms
memory: 305128kb
input:
186 228 1 2 1 3 5 6 5 8 9 11 9 12 13 14 13 15 13 16 17 18 18 19 21 23 22 23 25 26 25 27 26 27 29 32 30 31 33 34 33 36 34 35 37 39 37 40 38 39 41 42 41 43 41 44 42 43 45 46 46 48 49 51 50 52 53 54 53 55 54 56 57 60 58 60 61 62 61 64 62 64 65 67 65 68 66 68 69 70 69 71 69 72 70 72 74 75 74 76 77 78 78...
output:
18 4
result:
ok single line: '18 4'
Test #24:
score: 0
Accepted
time: 42ms
memory: 305096kb
input:
3 4 1 2 3 4 3 2
output:
1 0
result:
ok single line: '1 0'
Test #25:
score: -100
Wrong Answer
time: 28ms
memory: 303472kb
input:
5110 5065 1 2 1 3 6 7 6 9 11 13 11 14 16 17 16 18 16 19 21 22 21 25 26 28 26 30 31 32 31 33 31 35 36 39 36 40 41 42 41 44 41 45 46 48 46 49 46 50 51 52 51 53 51 54 51 55 56 57 57 58 61 63 62 63 66 67 66 68 67 68 71 74 72 73 76 77 76 79 77 78 81 83 81 84 82 83 86 87 86 88 86 89 87 88 91 95 92 93 96 9...
output:
178 104
result:
wrong answer 1st lines differ - expected: '142 140', found: '178 104'