Submission #411924

# Submission time Handle Problem Language Result Execution time Memory
411924 2021-05-26T09:15:45 Z kai824 Toy Train (IOI17_train) C++17
0 / 100
54 ms 1628 KB
#include "train.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<ll,ll>
#define mp make_pair
#define f first
#define s second

#ifdef local
#define deb(x) cerr<<x<<'\n';
#define debl(label,x) cerr<<label<<": "<<x<<'\n';
#else
#define deb(x) ;
#define debl(label,x) ;
#endif

vector<int> adjl[5005],adj[5005];

vector<int> st;
int lo[5005],mm[5005],cur,n;
int scc[5005],nex;
bool mk[5005],vis[5005];
int ch[5005];//no. of unprocessed children
void dfs(int nd,int prev=-1){
	debl("DFSing",nd)
	vis[nd]=true;
	lo[nd]=mm[nd]=cur++;
	st.push_back(nd);
	for(int x:adjl[nd]){
		if(vis[x]){//if scc is not labelled 0, can be diff tree
			if(scc[x]==0)mm[nd]=min(mm[nd],lo[x]);
			continue;
		}else if(x==prev){
			return;
		}
		dfs(x,nd);
		mm[nd]=min(mm[nd],mm[x]);
	}
	if(mm[nd]<lo[nd])return;//part of higher thing
	while(st.size()>0 && st.back()!=nd){
		scc[st.back()]=nex;
		st.pop_back();
	}
	mk[nex]=false;
	scc[st.back()]=nex++;st.pop_back();
}

bool dfs2(int x,int prev=-1){
	if(mk[x])return true;
	for(int i:adj[x]){
		if(i==prev)continue;
		if(dfs2(i,x))return true;
	}
	return false;
}

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
	vector<int> ans;
	n=a.size();
	for(int i=0;i<n;i++)scc[i]=0;
	for(int i=0;i<u.size();i++)adjl[u[i]].push_back(v[i]);
	cur=nex=1;
	for(int i=0;i<n;i++){
		if(vis[i]==false)dfs(i);//find SCCs
		deb("--------------------")
	}
	//for st3:
	for(int i=0;i<n;i++){
		if(r[i]==1)mk[scc[i]]=true;
	}
	/*
	//for st4:
	for(int i=1;i<nex;i++)mk[i]=false;
	for(int i=0;i<n;i++){
		if(r[i]==0)mk[scc[i]]=true;
	}
	*/
	for(int i=0;i<u.size();i++){
		adj[scc[u[i]]].push_back(scc[v[i]]);
	}
	for(int i=0;i<nex;i++){
		sort(adj[i].begin(),adj[i].end());
		adj[i].erase(unique(adj[i].begin(),adj[i].end()),adj[i].end());
	}
	for(int i=0;i<n;i++){
		ans.push_back(dfs2(scc[i]));
	}
	return ans;
}

Compilation message

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:62:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |  for(int i=0;i<u.size();i++)adjl[u[i]].push_back(v[i]);
      |              ~^~~~~~~~~
train.cpp:79:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |  for(int i=0;i<u.size();i++){
      |              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1484 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 1628 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1328 KB 3rd lines differ - on the 696th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1624 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1484 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -