Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
32830 | LYLAKIOI | 【S】T2 | C++ | 解答错误 | 50 | 286 MS | 10680 KB | 2633 | 2024-10-02 12:46:19 |
#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define p_b push_back #define m_p make_pair using namespace std; typedef long long ll; const int maxn=2e5+10; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; }int n,m,q,rt,cc,deg[maxn]; vector<int>v[maxn],g[maxn]; bitset<2005>B[2005]; vector<int>S[2005]; bool vis[maxn]; int dfn[maxn],low[maxn],stk[maxn],tp,instk[maxn],bel[maxn],ct; void dfs(int u){ dfn[u]=low[u]=++ct,stk[++tp]=u,instk[u]=1; for(int x:v[u]){ if(!dfn[x])dfs(x),low[u]=min(low[u],low[x]); else if(instk[x])low[u]=min(low[u],low[x]); }if(dfn[u]==low[u]){++cc; while(tp){ int x=stk[tp--]; instk[x]=0,bel[x]=cc; S[cc].p_b(x); if(x==u)break; } } } void topo(){ queue<int>q; up(i,1,cc)if(!deg[i])q.push(i); while(!q.empty()){ int u=q.front();q.pop(); for(int x:g[u]){ B[S[x][0]]|=B[S[u][0]]; if(!(--deg[x]))q.push(x); } } } int qry(int x,int y,int k){ if(!B[x][y])return -1; int u=x;vector<int>S;vis[x]=1; while(u!=y){ S.p_b(u);int nxt=-1; for(int w:v[u])if(B[w][y]){ nxt=w;break; }if(!vis[nxt])vis[nxt]=1; else { for(int w:S)vis[w]=0; return -1; }u=nxt; }S.p_b(y); for(int x:S)vis[x]=0; if(S.size()>=k)return S[k-1]; return -1; } void slv(){ n=read(),m=read(),q=read();int typ=read(); up(i,1,m){ int x=read(),y=read(); v[x].p_b(y); }up(i,1,n)sort(v[i].begin(),v[i].end()); up(i,1,n)if(!dfn[i])dfs(i); up(i,1,n)up(j,1,n)if(bel[i]==bel[j])B[i][j]=1; set<pi>st; up(i,1,n)for(int x:v[i])if(bel[i]!=bel[x]&&(!st.count(m_p(bel[i],bel[x])))){ st.insert(m_p(bel[i],bel[x])); g[bel[x]].p_b(bel[i]),++deg[bel[i]]; }topo(); up(i,1,cc)for(int x:S[i])B[x]=B[S[i][0]]; up(i,1,n)vis[i]=0;int lst=1; while(q--){ int x=read()^(lst*typ),y=read()^(lst*typ),k=read()^(lst*typ); x=x%n+1,y=y%n+1,k=k%n+1; int res=qry(x,y,k);lst=abs(res); printf("%d\n",res); } }int main(){ //freopen("path.in","r",stdin); //freopen("path.out","w",stdout); slv(); fclose(stdin); fclose(stdout); return 0; }