Submission #485476

#TimeUsernameProblemLanguageResultExecution timeMemory
485476PedroBigManToy Train (IOI17_train)C++14
11 / 100
1842 ms2500 KiB
#include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <string> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <queue> #include <deque> #include <list> #include "train.h" using namespace std; typedef int ll; typedef unsigned long long int ull; typedef long double ld; #define REP(i,a,b) for(ll i=(ll)a; i<(ll)b; i++) #define pb push_back #define mp make_pair #define pl pair<ll,ll> #define ff first #define ss second #define whole(x) x.begin(),x.end() #define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl #define INF 100000000000000000LL ll insig; #define In(vecBRO, LENBRO) REP(IBRO,0,LENBRO) {cin>>insig; vecBRO.pb(insig);} void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;} class DiGraph { public: ll N; vector<vector<ll> > adj; vector<bool> visited; ll target; bool cycle; DiGraph(vector<vector<ll> > ad) { adj=ad; N=adj.size(); REP(i,0,N) {visited.pb(false);} } void Reset() { REP(i,0,N) {visited[i]=false;} } void DFS(ll s) { if(visited[s]) {return;} visited[s]=true; REP(i,0,adj[s].size()) { if(!visited[adj[s][i]]) {DFS(adj[s][i]);} else if(adj[s][i]==target) {cycle=true;} } return; } }; vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) { ll N = a.size(); ll M = u.size(); vector<vector<ll> > adj1,adj2; REP(i,0,N) {adj1.pb({}); adj2.pb({});} REP(i,0,M) {adj1[u[i]].pb(v[i]); if(r[u[i]]==0 && r[v[i]]==0) {adj2[u[i]].pb(v[i]);}} DiGraph G1(adj1); DiGraph G2(adj2); vector<bool> cycle; REP(i,0,N) {cycle.pb(false);} REP(i,0,N) { G2.Reset(); G2.cycle=false; G2.target=i; G2.DFS(i); cycle[i]=G2.cycle; } vector<ll> ans; REP(i,0,N) {ans.pb(1);} REP(i,0,N) { G1.Reset(); G1.DFS(i); REP(j,0,N) {if(cycle[j] && G1.visited[j]) {ans[i]=0;}} } return ans; }
#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...