社区讨论

一种题解防止抄袭的方法

学术版参与者 8已保存回复 12

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
12 条
当前快照
1 份
快照标识符
@mlniomyc
此快照首次捕获于
2026/02/15 17:02
4 天前
此快照最后确认于
2026/02/16 11:12
3 天前
查看原帖
其实我们可以在题解给出的代码中随机插入 Unicode 0x200B 零宽间隔(一个不可见且不占空间的字符)来防止无脑 ctj 的小朋友?
比如这个:
CPP
#include<bits/stdc++​.h>
#define llong long long
#define N 20​0005
using namespace st​d;
​
#define bs (1<<20)
char buf[bs], *p1, *p2;
#define ​gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,bs,stdin),p1==p2)?EOF:*p1++)
template<typename T>
inline void read(T& x){
    x = 0; int w = 1;
    char ch = gc();
    while(ch < '0' || ch > '9'){
​        if(ch == '-') w = -w;
        ch = gc();
    }
    while(ch >=​ '0' && ch <= '9')
        x = (x<<3)+(x<<1)+(ch^48), ch = gc();
    x *= w;
}
template<typename T, typename ...Args>
inline void read(T& x, Args& ...y){
    return read(x), read(y...);
}
​
int to[N<<1], nxt[N<<1], head[N], gsiz;
#define mkarc(u,v)​ (++gsiz, to[gsiz]=v, nxt[gsiz]=head[u], head[u]=gsiz)
int fa[N], siz[N], son[N];
int vis[N], bl[N], tmp[N], tmpv[N], maxn, vcnt;
vector<int> tag[N], now;
int n, m, ans;

inline void prework(int u){
    siz[u] = 1;
    for(int i = head[u]; i; i = nxt[i]){
        int v = to[i];
        if(v == fa[u]) continue;
        fa[v] = u;
        prework(v);
        siz[u] += siz[v];
        if(siz[v] > siz[son[u]]) son[u] = v;
    }
    return;
}
inline void clear(){
    ++vcnt, maxn = 0;
    no​w.clear();
    return;
}
inline void record(int x){
    if(tmpv[x] != vcnt) tmp[x] = 1, tmpv[x] = vcnt;
 ​   else ++tmp[x];
    no​w.push_back(x);
    maxn = max(maxn, tmp[x]);
    return;
}
inline void dfs(int ​u){
    if(bl[u]) return;
    for(int i : tag[u]) 
        if(!vis[i]) record(i);
    for(int i = head[u]; i; i = nxt[i]){
   ​     int v = to[i];
        if(v == fa[u]) continue;
        dfs(v);
    }
    return;
}
inline void dsu(int u){
    for(int i = hea​d[u]; i; i = nxt[i]){
    ​    int v = to[i];
        if(v == fa[u​] || v == son[u]) continue;
        dsu(v);
    }
    clear();​
    if(son[u]) dsu(son[u]);
    for(int i : tag[u])
        if(!vis[i]) record(i);
    for(int i = head[u]; i; i = nxt[i]){
        int v = to[i];
      ​  if(v == fa[u] || v == son[u]) continue;
        dfs(v);
    }
    if(maxn >= 2){
     ​   bl[u] = true, ++ans;
        for(int i : no​w)
            vis[i] = ​true;
        clear();
    }
    return;
}

int main(){
   ​ read(​n, m);
    for(int i = 1; i < n; ++i){
      ​  int u, v; read(u, v);
​        mkarc(u, v), mkarc(v, u);
    }
    for(int i = 1; i​ <= m; ++i){
   ​     int u, v; read(u, v);
  ​    ​  tag[u].push_back(i);
        tag[v].push_back(i);
    }​
    prework(1),​ dsu(1);
    printf("%d\n", ans);
    for(int ​i = 1; i <= n; ++i)
        if(bl[i]) printf("%d ​", i);
  ​  return 0;
}

看着很正常,但是拿小号交一发:

回复

12 条回复,欢迎继续交流。

正在加载回复...