답안 #413035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
413035 2021-05-28T06:34:06 Z 조영욱(#7624) 장난감 기차 (IOI17_train) C++14
0 / 100
2000 ms 262148 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> adj[5000];
vector<int> gph[5000];
bool vis[5000];
int deg[5000];

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
    int n=a.size();
    int m=u.size();
    for(int i=0;i<m;i++) {
        gph[u[i]].push_back(v[i]);
    }
    vector<int> ret(n);
    for(int st=0;st<n;st++) {
        queue<int> q;
        q.push(st);
        memset(vis,0,sizeof(vis));
        vis[st]=true;
        while (!q.empty()) {
            int now=q.front();
            q.pop();
            for(int i=0;i<gph[now].size();i++) {
                int nt=gph[now][i];
                vis[nt]=true;
                q.push(nt);
            }
        }
        for(int i=0;i<n;i++) {
            adj[i].clear();
        }
        memset(deg,0,sizeof(deg));
        for(int i=0;i<m;i++) {
            if (r[u[i]]==0&&r[v[i]]==0&&vis[u[i]]&&vis[v[i]]) {
                adj[u[i]].push_back(v[i]);
                deg[v[i]]++;
            }
        }
        for(int i=0;i<n;i++) {
            if (deg[i]==0) {
                q.push(i);
            }
        }
        int cnt=0;
        while (!q.empty()) {
            int now=q.front();
            q.pop();
            cnt++;
            for(int i=0;i<adj[now].size();i++) {
                int nt=adj[now][i];
                deg[nt]--;
                if (deg[nt]==0) {
                    q.push(nt);
                }
            }
        }
        ret[st]=(cnt==n);
    }
    return ret;
}

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:25:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |             for(int i=0;i<gph[now].size();i++) {
      |                         ~^~~~~~~~~~~~~~~~
train.cpp:51:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             for(int i=0;i<adj[now].size();i++) {
      |                         ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2004 ms 262148 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2079 ms 460 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1728 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1544 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1270 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2004 ms 262148 KB Time limit exceeded
2 Halted 0 ms 0 KB -