답안 #1076794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1076794 2024-08-26T16:38:58 Z zehnsechs 장난감 기차 (IOI17_train) C++14
38 / 100
2000 ms 6560 KB
#include "train.h"
#include<bits/stdc++.h>

using namespace std;


void dfs(int v, vector<int>& x, vector<int>& c, vector<vector<int>>& adj, vector<int>& res){
    if(res[v]) return;
    res[v]=1;
    //cerr << "vertex " << v << '\n';    
    if(res[v]){
        for(int u: adj[v]){
            cerr << "n " << u << '\n';
            if (u==v) continue;
            c[u]--;
            if(c[u]==0 && !res[u]) {
                dfs(u,x,c,adj,res);
            }
        }
    }
}


vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
	int n = a.size();
        int m = u.size();
        vector<int> res(n,1);
        vector<vector<int>> adj(n);
        vector<int> deg(n,0);
        
        //add the edges to adj in the opposite direction
        for(int i=0;i<m;++i){
            //cerr << "edge " << u[i] << ' ' << v[i] << '\n';
            adj[v[i]].push_back(u[i]);
            deg[u[i]]++;
        }
        
        bool con = true;
        while(con){
            con = false;
            vector<int> fa(n,0);
            vector<int> rm(n,0);
            vector<int> c0(n,1);
            vector<int> c1(n,1);
            
            for(int i=0;i<n;++i) (a[i] ? c1[i] = deg[i] : c0[i]= deg[i]);
            //cerr << "fa" << '\n';
            for(int i=0;i<n;++i) if(r[i]&&res[i]) dfs(i,r,c0,adj,fa);
            vector<int> x(n,0);
            for(int i=0;i<n;++i) if(!fa[i]) x[i]=1;
            //cerr << "fb" << '\n';
            
            for(int i=0;i<n;++i) if(!fa[i]&&res[i]) dfs(i,x,c1,adj,rm);
            for(int i=0;i<n;++i) if(rm[i]) {
                //cerr << "unreachable " << i <<'\n';
                for(int u: adj[i]) deg[u]--;
                adj[i].clear();
                res[i]=0;
                con = true;
                }
        }



	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 1116 KB Output is correct
2 Correct 107 ms 1192 KB Output is correct
3 Correct 90 ms 1112 KB Output is correct
4 Correct 85 ms 1112 KB Output is correct
5 Correct 70 ms 1176 KB Output is correct
6 Correct 67 ms 1156 KB Output is correct
7 Correct 35 ms 1116 KB Output is correct
8 Correct 108 ms 1116 KB Output is correct
9 Correct 54 ms 1116 KB Output is correct
10 Correct 39 ms 1116 KB Output is correct
11 Correct 27 ms 1104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 436 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 432 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2072 ms 6560 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 1360 KB Output is correct
2 Correct 112 ms 1568 KB Output is correct
3 Correct 83 ms 1492 KB Output is correct
4 Correct 103 ms 1620 KB Output is correct
5 Correct 102 ms 1636 KB Output is correct
6 Correct 108 ms 1616 KB Output is correct
7 Correct 109 ms 1580 KB Output is correct
8 Correct 79 ms 1616 KB Output is correct
9 Correct 102 ms 1620 KB Output is correct
10 Correct 61 ms 1620 KB Output is correct
11 Correct 65 ms 1620 KB Output is correct
12 Correct 70 ms 1512 KB Output is correct
13 Correct 99 ms 1620 KB Output is correct
14 Correct 99 ms 1620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 1616 KB Output is correct
2 Correct 63 ms 1872 KB Output is correct
3 Correct 111 ms 1616 KB Output is correct
4 Correct 56 ms 1368 KB Output is correct
5 Correct 11 ms 508 KB Output is correct
6 Correct 23 ms 1116 KB Output is correct
7 Correct 97 ms 1128 KB Output is correct
8 Correct 89 ms 1116 KB Output is correct
9 Correct 88 ms 1144 KB Output is correct
10 Correct 27 ms 600 KB Output is correct
11 Correct 90 ms 1048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 1116 KB Output is correct
2 Correct 107 ms 1192 KB Output is correct
3 Correct 90 ms 1112 KB Output is correct
4 Correct 85 ms 1112 KB Output is correct
5 Correct 70 ms 1176 KB Output is correct
6 Correct 67 ms 1156 KB Output is correct
7 Correct 35 ms 1116 KB Output is correct
8 Correct 108 ms 1116 KB Output is correct
9 Correct 54 ms 1116 KB Output is correct
10 Correct 39 ms 1116 KB Output is correct
11 Correct 27 ms 1104 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 436 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 440 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 432 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Execution timed out 2072 ms 6560 KB Time limit exceeded
33 Halted 0 ms 0 KB -