Submission #485474

#TimeUsernameProblemLanguageResultExecution timeMemory
485474PedroBigManToy Train (IOI17_train)C++14
11 / 100
1481 ms1928 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> > adj; REP(i,0,N) {adj.pb({});} REP(i,0,M) {adj[u[i]].pb(v[i]);} DiGraph G(adj); vector<bool> cycle; REP(i,0,N) {cycle.pb(false);} REP(i,0,N) { if(r[i]==0) {continue;} G.Reset(); G.cycle=false; G.target=i; G.DFS(i); cycle[i]=G.cycle; } vector<ll> ans; REP(i,0,N) {ans.pb(0);} REP(i,0,N) { G.Reset(); G.DFS(i); REP(j,0,N) {if(cycle[j] && G.visited[j]) {ans[i]=1;}} } 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...