Special Judge

Laffey 2022-11-16 11:10:28

用的是测试数据里的 spj,因为 SYZOJ 并不使用 testlib,所以进行了些许修改。

不过评测逻辑肯定是与原 checker 完全相同的。

#include <iostream>
#include <fstream>
#include <vector>
#include <cstdarg>
#include <string>
#include <cstdlib>
using namespace std;

// Because SYZOJ does not use "testlib", we must edit the checker to be used on SYZOJ.
// Edited By Laffey.

// Do nothing because the files are given.
inline void registerTestlibCmd(int argc, char **argv) { }

// Use <iostream> in STL.
struct InStream {
    ifstream fin;

    // Note that we use mode ios_base::in to read the file.
    InStream(string input_file)
    {
        fin.open(input_file, ios_base::in);
    }

    ~InStream() { }

    // Read an integer from stream.
    int readInt()
    {
        int ans;
        fin >> ans;
        return ans;
    }
};

// Use filenames on SYZOJ to replace them.
InStream inf("input");
InStream ouf("user_out");
InStream ans("answer");

// Declaration for TResult.
enum TResult {
    _ok = 0,
    _wa = 1,
    _pe = 2,
    _fail = 3,
    _dirt = 4,
    _points = 5,
    _unexpected_eof = 8,
    _partially = 16
};

// To quit the checker and print some messages.
void quitf(TResult result, const char *format, ...)
{
    va_list v;
    switch (result) {
        case _ok:
            cout << 100;
            break;
        default:
            cout << 0;
            break;
    }
    // To use the format string, we must use fprintf.
    fprintf(stderr, format, v);
    exit(0);
}

// Here's the raw checker.

int n,b,k,cnt,num[10001],vis[10001];
vector<int> G[10001],v[10001];
void dfs(int x,int fa)
{
	cnt-=vis[x];
	vis[x]=0;
	for(int i:G[x])
		if(i!=fa&&vis[i])
			dfs(i,x);
}
int main(int argc, char* argv[])
{
	registerTestlibCmd(argc, argv);
	n=inf.readInt();
	b=inf.readInt();
	for(int i=1;i<n;i++)
	{
		int x=inf.readInt(),y=inf.readInt();
		G[x].push_back(y);
		G[y].push_back(x);
	}
	k=ouf.readInt();
	if(!k)
		quitf(_wa,"wujie");
	if(k>n)
		quitf(_wa,"k is too big");
	for(int i=1;i<=n;i++)
	{
		int x=ouf.readInt();
		if(x<0||x>k)
			quitf(_wa,"invalid1: %d",i);
		v[x].push_back(i);
		num[x]++;
	}
	for(int i=1;i<=k;i++)
		if(num[i]<b||num[i]>2*b)
			quitf(_wa,"size");
	for(int i=1;i<=k;i++)
	{
		int x=ouf.readInt();
		if(x<0||x>n)
			quitf(_wa,"invalid2: %d",i);
		v[i].push_back(x);
		for(int l:v[i])
			vis[l]++;
		cnt=num[i]+1;
		dfs(x,0);
		if(cnt)
			quitf(_wa,"disconnect: %d",i);
	}
	quitf(_ok,"AC");
	return 0;
}