제출 #72898

#제출 시각아이디문제언어결과실행 시간메모리
72898mr_banana장난감 기차 (IOI17_train)C++17
0 / 100
300 ms26460 KiB
#include "train.h" #include<bits/stdc++.h> using namespace std; const int MN=5000+100; bool g[MN][MN]; vector<int> adj[MN],radj[MN]; vector<int> topol; bool mark[MN]; int cmp[MN],szcmp[MN]; int n,m; void dfs(int v){ mark[v]=1; for(int u:adj[v]){ if(!mark[u]){ dfs(u); } } topol.push_back(v); } void dfs2(int v,int cmpn){ mark[v]=1; cmp[v]=cmpn; szcmp[cmpn]++; for(int u:radj[v]){ if(!mark[u]){ dfs2(u,cmpn); } } } void scc(){ for(int i=0;i<n;i++){ if(!mark[i]){ dfs(i); } } memset(mark,0,sizeof mark); int cnt=0; for(int i=n-1;i>=0;i--){ if(!mark[topol[i]]){ dfs2(topol[i],cnt); cnt++; } } } void dfs3(int v){ mark[v]=1; for(int i=0;i<n;i++){ if(!mark[i] && g[i][v]){ dfs3(i); } } } vector<int> who_wins(vector<int> a,vector<int> r,vector<int> u,vector<int> v) { vector<int> res(a.size()); n=a.size(),m=v.size(); for(int i=0;i<m;i++){ g[u[i]][v[i]]=1; adj[u[i]].push_back(v[i]); radj[v[i]].push_back(u[i]); } scc(); memset(mark,0,sizeof mark); for(int i=0;i<n;i++){ if(!mark[i] && r[i] && szcmp[cmp[i]]>1){ dfs3(i); } } for(int i=0;i<n;i++){ res[i]=mark[i]; } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...