답안 #261742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261742 2020-08-12T03:53:17 Z tqbfjotld Colors (RMI18_colors) C++14
0 / 100
1050 ms 8952 KB
#include <bits/stdc++.h>
using namespace std;

int init[150005];
int fin[150005];
vector<int> adjl[150005];
vector<pair<int,int> > order;
queue<pair<int,int> > q;
bool visited[150005];
int counter = 0;

bool dfs(int node, int findcol, int finx){
    if (init[node]==findcol) return true;
    visited[node] = true;
    counter++;
    assert(counter<=5000000);
    for (auto x : adjl[node]){
        if (init[x]<finx || fin[x]>finx) continue;
        if (!visited[x]){
            if (dfs(x,findcol,finx)) return true;
        }
    }
    return false;
}

int main(){
int test;
scanf("%d",&test);
while (test--){
    int n,m;
    scanf("%d%d",&n,&m);
    for (int x = 1; x<=n; x++){
        scanf("%d",&init[x]);
        adjl[x].clear();
    }
    bool poss1 = true;
    for (int x = 1; x<=n; x++){
        scanf("%d",&fin[x]);
        if (fin[x]>init[x]) poss1 = false;
        order.push_back({fin[x],x});
    }
    sort(order.begin(),order.end(),greater<pair<int,int> >());
    for (int x = 0; x<m; x++){
        int a,b;
        scanf("%d%d",&a,&b);
        adjl[a].push_back(b);
        adjl[b].push_back(a);
    }
    if (!poss1) {
        printf("0\n");
        continue;
    }
    bool poss = true;
    for (auto x : order){
        for (int x = 1; x<=n; x++) visited[x] = false;
        if (!dfs(x.second,fin[x.second],fin[x.second])){
            printf("0\n");
            poss = false;
            break;
        }
    }
    if (poss){
        printf("1\n");
    }
}
}

Compilation message

colors.cpp: In function 'int main()':
colors.cpp:28:6: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf("%d",&test);
 ~~~~~^~~~~~~~~~~~
colors.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
colors.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&init[x]);
         ~~~~~^~~~~~~~~~~~~~~
colors.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&fin[x]);
         ~~~~~^~~~~~~~~~~~~~
colors.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 311 ms 8312 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 219 ms 8952 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1050 ms 8844 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1050 ms 8844 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 311 ms 8312 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 335 ms 8516 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 154 ms 8568 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 311 ms 8312 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -