# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
290409 | Autoratch | Bitaro’s Party (JOI18_bitaro) | C++14 | 2072 ms | 466396 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
const int K = 1001;
int n,m,k;
vector<int> adj[N],rev[N];
int deg[N],id[N];
queue<int> q;
vector<pair<int,int> > res[N];
bool out[N];
stack<int> st;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> k;
for(int i = 0;i < m;i++)
{
int a,b;
cin >> a >> b;
deg[b]++;
adj[a].push_back(b);
rev[b].push_back(a);
}
for(int i = 1;i <= n;i++) if(!deg[i]) q.push(i);
while(!q.empty())
{
int u = q.front();
q.pop();
for(int v : rev[u]) id[v] = 0;
for(int j = 0;j < K;j++)
{
pair<int,int> mx = {u,0};
for(int v : rev[u])
{
while(id[v]<res[v].size() and out[res[v][id[v]].first]) id[v]++;
if(id[v]<res[v].size() and res[v][id[v]].second+1>mx.second) mx = {res[v][id[v]].first,res[v][id[v]].second+1};
}
res[u].push_back(mx);
out[mx.first] = true;
st.push(mx.first);
if(mx.first==u) break;
else id[mx.first]++;
}
while(!st.empty()) out[st.top()] = false,st.pop();
for(int v : adj[u])
{
deg[v]--;
if(deg[v]==0) q.push(v);
}
}
while(k--)
{
int u,am;
cin >> u >> am;
while(am--){ int x; cin >> x; out[x] = true; st.push(x); }
if(am>=K)
{
//for(int i = 1;i <= n;i++) deg[i] = adj[i].size();
}
else
{
int ans = -1;
for(auto [x,y] : res[u]) if(!out[x]){ ans = y; break; }
cout << ans << '\n';
}
while(!st.empty()) out[st.top()] = false,st.pop();
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |