QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#791973 | #9810. Obliviate, Then Reincarnate | Clclclcl | WA | 2ms | 22864kb | C++20 | 3.1kb | 2024-11-28 22:39:37 | 2024-11-28 22:39:37 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
using ll = long long;
# define int long long
# define endl '\n'
# define cy cout << "Yes" << endl
# define cn cout << "No" << endl
# define pb push_back
# define fi first
# define se second
# define in insert
# define all(a) a.begin(), a.end()
# define rep(i,a,n) for (int i = a;i <= n;i ++)
# define per(i,a,n) for (int i = n;i >= a;i --)
typedef pair<int,int> PII;
typedef double db;
const int N = 5e5 + 10;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int INF = 1e17;
priority_queue<ll,vector<ll>, greater<ll> > mi;
priority_queue<ll> ma;
vector <int> g[N],ng[N];
vector <int> pos[N];
int n,m,k;
int dfn[N],low[N],tim;
int stk[N],top;
bool in_stk[N];
int dout[N],din[N];
int id[N],cnt,Size[N];
int dp[N],w[N],nw[N];
int f[N];
void tarjan(int u){
dfn[u] = low[u] = ++ tim;
stk[ ++ top] = u,in_stk[u] = true;
for (auto l : 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].pb(y);
}while(y != u);
}
}
void solve() {
vector <vector <PII>> g2(N + 1);
cin >> n >> m >> k;
for(int i = 1;i <= m;i ++ ){
int l,r;
cin >> l >> r;
int w = r;
l = ((l + n) % n);
r = ((l + r) + n) % n;
l ++;
r ++;
//cout << l << r << endl;
g2[l].pb({r,w});
g[l].pb(r);
}
for(int i = 1;i <= n;i ++ ){
if(!dfn[i]) tarjan(i);
}
for(int i = 1;i <= cnt;i ++ ){
int a = id[i];
for(auto l : g[i]){
int b = id[l];
if(a != b){
ng[b].pb(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{
st[u] = 1;
for(auto [l,w] : g2[u]){
if(id[l] != p) continue;
if(st[l]){
if(dist[u] + w != dist[l]){
//cout << dist[l] + w << ' ' << dist[u] << endl;
//cout << l << ' ' << u << endl;
ok[p] = 1;
}
return;
}
dist[l] = dist[u] + w;
dfs(dfs,l,p);
}
};
for(int i = 1;i <= cnt;i ++ ){
cout << pos[i][0] << endl;
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 + 1;
//cout << l;
l = id[l];
if(ok[l]) cy;
else cn;
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int _ = 1;
//cin >> _ ;
while( _ -- )
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 22864kb
input:
3 2 3 1 1 -1 3 1 2 3
output:
1 3 2 Yes Yes No
result:
wrong answer 1st words differ - expected: 'Yes', found: '1'