QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#792940#9807. Make Them BelievezijinjunRE 0ms0kbC++173.2kb2024-11-29 15:13:122024-11-29 15:13:16

Judging History

你现在查看的是最新测评结果

  • [2024-11-29 15:13:16]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-29 15:13:12]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <unordered_set>
#include <functional>
#include <stack>
#include <unordered_map>
#include <map>
#include <cmath>
#include <cstring>
#include <set>
using namespace std;

inline int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c > '9' || c < '0')
        f = c == '-' ? -1 : 1, c = getchar();
    while (c >= '0' && c <= '9')
        x = x * 10 + c - 48, c = getchar();
    return x * f;
}
using i64 = long long;
using u64 = unsigned long long;
using pii = pair<int, int>;
using pll = pair<i64, i64>;
priority_queue<i64,vector<i64>, greater<i64> > mi;
priority_queue<i64> ma;

const int N = 5e5 + 10;
vector <pii> g[N];
vector <int> pos[N],ng[N];
int n,m,k;
int dfn[N],low[N],tim, stk[N],top;
bool in_stk[N];
int din[N], id[N],cnt,Size[N], f[N];

void tarjan(int u){
    dfn[u] = low[u] = ++ tim;
    stk[ ++ top] = u,in_stk[u] = true;

    for (auto [l,w] : g[u]){
        if (!dfn[l]){
            tarjan(l);
            low[u] = min(low[u],low[l]);
        }
        else if (in_stk[l]) low[u] = min(low[u],dfn[l]);
    }

    if (dfn[u] == low[u]){
        ++ cnt;
        int y;
        do{
            y = stk[top --];
            in_stk[y] = false;
            id[y] = cnt;
            Size[cnt] ++;
            pos[cnt].push_back(y);
        }while(y != u);
    }
}

void solve() {
    cin >> n >> m >> k;
    for(int i = 1;i <= m;i ++ ){
        int l,r;
        cin >> l >> r;
        int l1 = ((l % n + n) % n);
        int r1 = ((l + r) % n + n) % n;
        l1 ++;
        r1 ++;
        g[l1].push_back({r1,r});
    }

    for(int i = 1;i <= n;i ++ ){
        if(!dfn[i]) tarjan(i);
    }

    for(int i = 1;i <= n;i ++ ){
        int a = id[i];
        for(auto [l,w] : g[i]){
            int b = id[l];
            if(a != b){
                ng[b].push_back(a);
                din[a] ++;
            }
        }
    }

    vector <int> ok(n + 1,0);
    vector <bool> st(n + 1,0);
    vector <int> dist(n + 1,0);
    auto dfs = [&] (auto dfs,int u,int p) -> void{
        for(auto [l,w] : g[u]){
            if(id[l] != p) continue;
            if(st[l]){
                if(dist[u] + w != dist[l]){
                    ok[p] = 1;
                    return;
                }
                continue;
            }
            dist[l] = dist[u] + w;
            st[l] = 1;
            dfs(dfs,l,p);
        }
    };

    for(int i = 1;i <= cnt;i ++ ){
        dfs(dfs,pos[i][0],i);
    }

    auto topsort = [&] () -> void{
        queue <int> q;
        for(int i = 1;i <= cnt;i ++ ){
            if(!din[i]) q.push(i);
        }

        while(q.size()){
            auto u = q.front();
            q.pop();

            for(auto l : ng[u]){
                (ok[l] |= ok[u]);
                if(-- din[l] == 0) q.push(l);
            }
        }
    };
    topsort();

    while(k -- ){
        int l;
        cin >> l;
        l = (l % n + n) % n + 1;
        l = id[l];
        if(ok[l]) puts("Yes");
        else puts("No");
    }
}
signed main() {
    int T = read();
    while( T-- )
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

LNG 55
WBG 65
HLE 70
BLG 75
TES 48
T1 80
GEN 60
FLY 50

output:


result: