QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#798646#9810. Obliviate, Then Reincarnateucup-team4975WA 0ms3644kbC++232.7kb2024-12-04 15:40:382024-12-04 15:40:39

Judging History

This is the latest submission verdict.

  • [2024-12-04 15:40:39]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3644kb
  • [2024-12-04 15:40:38]
  • Submitted

answer

#define LOCAL
#include <bits/stdc++.h>
#define fir first
#define sec second
#define el '\n'

#ifdef LOCAL
#define FINISH cerr << "FINISH" << endl;
#else
#define FINISH ;
#endif

#ifdef LOCAL
#define debug(x) cerr << setw(4) << #x << " == " << x << endl
#else
#define debug(x)
#endif

#ifdef LOCAL
#define debugv(x)                   \
    cerr << setw(4) << #x << ":: "; \
    for (auto i : x)                \
        cerr << i << " ";           \
    cerr << endl
#else
#define debugv(x)
#endif

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
ostream& operator<<(ostream& out, PII& x)
{
    out << x.fir << " " << x.sec << endl;
    return out;
}
#define int long long
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const int N = 200020;
int id(int x, int n) {
	return (x % n + n) % n + 1;
}
void solve()
{
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<PII>> edge(n + 1);
    for (int i = 1; i <= m; i++) {
    	int x, y;
    	cin >> x >> y;
    	edge[id(x, n)].push_back(PII(id(y + x, n), y));
        cout << id(x, n) << " " << id(y + x, n) << " " << y << endl;
    }

    vector<int> dfn(n + 1, 0), low(n + 1, 0), col(n + 1, 0), val(n + 1, 0), stk;

    int cnt = 0, tot = 0;
    auto dfs = [&] (auto &self, int x) -> void {
    	dfn[x] = low[x] = ++tot;
    	stk.push_back(x);
    	for (auto [to, w] : edge[x]) {
    		val[to] = val[x] + w;
    		if (!dfn[to]) {
    			self(self, to);
    			low[x] = min(low[x], low[to]);
    		}
    		else if (!col[to]) {
    			low[x] = min(low[x], dfn[to]);
    		}
    	}
    	if (dfn[x] == low[x]) {
    		int y;
    		cnt++;
    		do {
    			y = stk.back();
    			col[y] = cnt;
    			stk.pop_back();
    		} while (y != x);
    	}
    };

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

    vector<int> ans(n + 1, 0);
    vector<vector<int>> g(n + 1);
    for (int i = 1; i <= n; i++) {
    	for (auto [to, w] : edge[i]) {
    		if (col[i] != col[to]) {
    			g[col[to]].push_back(col[i]);
    		}
    		if (col[i] == col[to] && val[i] + w != val[to]) {
    			ans[col[i]] = 1;
    		}
    	}
    }

    for (int i = 1; i <= cnt; i++) {
    	if (ans[i])
	    	for (auto to : g[i]) {
	    		ans[to] = 1;
	    	}
    }

    for (int i = 1; i <= q; i++) {
    	int x;
    	cin >> x;
    	x = id(x, n);
    	if (ans[col[x]] == 1)
    		cout <<"Yes" <<el;
    	else 
    		cout << "No" << el;
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3644kb

input:

3 2 3
1 1
-1 3
1
2
3

output:

2 3 1
3 3 3
Yes
Yes
No

result:

wrong answer 1st words differ - expected: 'Yes', found: '2'