답안 #485475

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485475 2021-11-08T00:50:52 Z PedroBigMan 장난감 기차 (IOI17_train) C++14
0 / 100
1888 ms 2380 KB
#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]] && !r[v[i]]) {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(0);}
	REP(i,0,N)
	{
		G1.Reset(); G1.DFS(i); 
		REP(j,0,N) {if(cycle[j] && G1.visited[j]) {ans[i]=1;}}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 294 ms 1672 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 420 ms 2380 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 798 ms 1488 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1888 ms 2196 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 294 ms 1672 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -