提供一个有解情况下的 checker
查看原帖
提供一个有解情况下的 checker
881015
Resstifnurvˆwˆ.tar.gz楼主2024/6/25 20:57
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

// #define IS_ATCODER
// #define IS_MULTI_TESTS
#define USE_CIN

/*
#ifndef ONLINE_JUDGE
#include <atcoder/all>
using mint = atcoder::modint998244353;
#else
#ifdef IS_ATCODER
#include <atcoder/all>
using mint = atcoder::modint998244353;
#endif
#endif
*/

#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
using ll = long long;
using pii = pair <int, int>;

inline int read(){
    int ret = 0;
    char ch = ' ', c = getchar();
    while(!('0' <= c && c <= '9')) ch = c, c = getchar();
    while('0' <= c && c <= '9'){
        ret = ret * 10 + (c ^ 48);
        c = getchar();
    }
    return ch == '-' ? -ret : ret;
}

int n, m;
const int N = 2e5 + 10;
const int M = 4e5 + 10;
int col[N];
bool sat[N];

struct edge{
    int x, y, z;
} e[N];

int p[N];
int find(int x){
    if(x != p[x]) p[x] = find(p[x]);
    return p[x];
}
inline void merge(int x, int y){
    int gx = find(x), gy = find(y);
    if(gx != gy) p[gy] = gx;
}
inline bool check(int x, int y){
    int gx = find(x), gy = find(y);
    return (gx == gy);
}

void solve(){
    // 测试数据文件
    freopen("03_rnd_05.in", "r", stdin);
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        int x, y, z;
        char chz;
        cin >> x >> y >> chz;
        if(chz == 'R') z = 0;
        else z = 1;
        e[i] = (edge){x, y, z};
    }
    string str;
    cin >> str;
    for(int i = 0; i < n; i++){
        if(str[i] == 'R') col[i + 1] = 0;
        else col[i + 1] = 1;
    }
    fclose(stdin);
    for(int i = 1; i <= n; i++) p[i] = i;
    // 答案文件
    // 仅用于测试答案为 Yes 的输出是否合法。
    freopen("03_rnd_05.txt", "r", stdin);
    cin >> str;
    if(str == "No") return ;
    for(int i = 1; i < n; i++){
        int id;
        cin >> id;
        int x = e[id].x, y = e[id].y, z = e[id].z;
        if(check(x, y)){
            cout << "Wrong Answer: Not a tree." << endl;
            return ;
        }
        merge(x, y);
        if(z == col[x]) sat[x] = true;
        if(z == col[y]) sat[y] = true;
    }
    for(int i = 1; i <= n; i++){
        if(!sat[i]){
            cout << "Wrong Answer: Conditions not satisfied." << endl;
            return ;
        }
    }
    cout << "Accepted." << endl;
}

int main(){
#ifdef USE_CIN
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
#endif
#ifdef IS_MULTI_TESTS
    int T = read();
    while(T--) solve();
#else
    solve();
#endif
    return 0;
}
2024/6/25 20:57
加载中...