QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#287628 | #1256. Delete Two Vertices Again | Dualqwq | WA | 0ms | 48736kb | C++20 | 2.5kb | 2023-12-20 20:43:31 | 2023-12-20 20:43:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5,M = 6e5 + 5,Lg = 19;
int n,m;
int fir[N],nxt[M],to[M],ect = 1;
inline void addedge(int u1,int v1) {
nxt[++ect] = fir[u1];fir[u1] = ect;to[ect] = v1;
}
int U[M],V[M];
vector<int> par[N],G[N];
bool vst[N];
int dep[N];
const int Sz = M << 5;
int rt[N],lc[Sz],rc[Sz],sum[Sz],tot = 0;
void insert(int &k,int l,int r,int pos,int v) {
if(!k) k = ++tot;
sum[k] += v;
if(l == r) return;
int mid = l + r >> 1;
if(pos <= mid) insert(lc[k],l,mid,pos,v);
else insert(rc[k],mid + 1,r,pos,v);
}
int Merge(int x,int y) {
if(!x || !y) return x + y;
int p = ++tot;
sum[p] = sum[x] + sum[y];
lc[p] = Merge(lc[x],lc[y]);
rc[p] = Merge(rc[x],rc[y]);
return p;
}
int Query(int k,int l,int r,int x,int y) {
if(!k || x > y) return 0;
if(x <= l && r <= y) return sum[k];
int mid = l + r >> 1;
if(y <= mid) return Query(lc[k],l,mid,x,y);
else if(x > mid) return Query(rc[k],mid + 1,r,x,y);
else return Query(lc[k],l,mid,x,y) + Query(rc[k],mid + 1,r,x,y);
}
int anc[Lg][N];
int sze[N];
void dfs(int x) {
vst[x] = true;sze[x] = 1;//printf("anc[0][%d]=%d,%d\n",x,anc[0][x],dep[x]);
for(int i = 1;i < Lg;i++) anc[i][x] = anc[i - 1][anc[i - 1][x]];
for(auto y : par[x])
if(vst[y]) insert(rt[x],1,n,dep[y],1);
for(int i = fir[x],y;y = to[i],i;i = nxt[i])
if(!vst[y]) {
G[x].push_back(y);
anc[0][y] = x;
dep[y] = dep[x] + 1;
dfs(y);sze[x] += sze[y];
rt[x] = Merge(rt[x],rt[y]);
// printf("%d->%d\n",x,y);
}
}
inline int jump(int x,int y) {
for(int i = Lg - 1;i >= 0;i--)
if(dep[anc[i][x]] > dep[y]) x = anc[i][x];
return x;
}
inline bool Ask(int u,int v) {
if(dep[u] > dep[v]) swap(u,v);
int pp = jump(v,u);
// printf("jp:%d,%d,%d,%d,%d\n",u,v,pp,dep[u],dep[v]);
if(u != 1) {
for(auto t : G[u])
if(t != pp && !Query(rt[t],1,n,1,dep[u] - 1)) return false;
}
else {
if(G[u].size() > 2) return false;
if(G[u].size() == 2 && (pp != v || G[v].size())) return false;
}
if(pp != v && sze[pp] != 1 && u != 1 && !(Query(rt[pp],1,n,1,dep[u] - 1) - Query(rt[v],1,n,1,dep[u] - 1))) return false;
for(auto t : G[v])
if(sze[t] != n - 2 && !Query(rt[t],1,n,1,dep[v] - 1)) return false;
return true;
}
int main() {
cin >> n >> m;
for(int i = 1;i <= m;i++) {
cin >> U[i] >> V[i],addedge(U[i],V[i]),addedge(V[i],U[i]);
par[U[i]].push_back(V[i]);
par[V[i]].push_back(U[i]);
}
dfs(1);
for(int i = 1;i <= m;i++)
if(Ask(U[i],V[i])) putchar('1'); else putchar('0');
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 48616kb
input:
4 4 1 2 2 3 3 1 4 1
output:
0101
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #2:
score: 0
Accepted
time: 0ms
memory: 46652kb
input:
3 3 1 2 2 3 3 1
output:
111
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #3:
score: 0
Accepted
time: 0ms
memory: 48680kb
input:
3 2 1 2 2 3
output:
11
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #4:
score: 0
Accepted
time: 0ms
memory: 48736kb
input:
6 7 1 2 1 3 1 6 2 4 3 4 3 5 4 6
output:
1011011
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 46700kb
input:
10 39 1 2 1 3 1 5 1 6 1 7 1 8 1 9 1 10 2 3 2 4 2 5 2 6 2 9 2 10 3 5 3 6 3 7 3 8 3 10 4 5 4 6 4 7 4 9 4 10 5 6 5 7 5 8 5 9 5 10 6 7 6 8 6 9 6 10 7 8 7 9 7 10 8 9 8 10 9 10
output:
111111111111101111011110111101110110101
result:
wrong answer Deleting vertices 2 and 10 makes graph connected, but participant claims otherwise.