QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#287656 | #1256. Delete Two Vertices Again | Dualqwq | WA | 8ms | 40352kb | C++20 | 2.8kb | 2023-12-20 21:15:26 | 2023-12-20 21:15:26 |
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) {
int p = ++tot;
sum[p] = sum[x] + sum[y];
return p;
}
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\n",u,v,pp);
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(u == 10 && v == 2) puts("d1");
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;
// if(u == 10 && v == 2) puts("d2");
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]);
}
dep[1] = 1;dfs(1);
for(int i = 1;i <= m;i++)
if(Ask(U[i],V[i])) putchar('1'); else putchar('0');
return 0;
}
/*
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 40344kb
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: 40296kb
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: 8ms
memory: 38356kb
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: -100
Wrong Answer
time: 4ms
memory: 40352kb
input:
6 7 1 2 1 3 1 6 2 4 3 4 3 5 4 6
output:
1010010
result:
wrong answer Deleting vertices 2 and 4 makes graph connected, but participant claims otherwise.