답안 #54896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
54896 2018-07-05T09:09:52 Z 강태규(#1507) Potemkin cycle (CEOI15_indcyc) C++11
70 / 100
1000 ms 5740 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int n, m;
vector<int> edge[1001];
int con[1001][1001];
int a[100001], b[100001];
int dist[1001];
int pr[1001];
int del[1001];

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", a + i, b + i);
        edge[a[i]].push_back(b[i]);
        edge[b[i]].push_back(a[i]);
        con[a[i]][b[i]] = con[b[i]][a[i]] = 1;
    }
    
    while (m--) {
        int a = ::a[m];
        int b = ::b[m];
        edge[a].pop_back();
        edge[b].pop_back();
        for (int i = 1; i <= n; ++i) {
            del[i] = (con[a][i] & con[b][i]);
            dist[i] = n;
        }
        
        priority_queue<pii, vector<pii>, greater<pii>> pq;
        dist[a] = 0;
        pq.emplace(0, a);
        while (!pq.empty()) {
            int x, d;
            tie(d, x) = pq.top();
            pq.pop();
            if (x == b) {
                while (x != a) {
                    printf("%d ", x);
                    x = pr[x];
                }
                printf("%d\n", a);
                return 0;
            }
            d = -d;
            if (d != dist[x]) continue;
            for (int i : edge[x]) {
                if (del[i]) continue;
                int nd = d + 1;
                if (nd < dist[i]) {
                    dist[i] = nd;
                    pr[i] = x;
                    pq.emplace(-nd, i);
                }
            }
        }
    }
    
    printf("no\n");
	return 0;
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
indcyc.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", a + i, b + i);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 3 ms 564 KB Output is correct
5 Correct 3 ms 564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 568 KB Output is correct
2 Correct 3 ms 568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1124 KB Output is correct
2 Correct 13 ms 1124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 190 ms 1896 KB Output is correct
2 Correct 12 ms 1900 KB Output is correct
3 Correct 7 ms 1904 KB Output is correct
4 Correct 30 ms 1904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 1904 KB Output is correct
2 Correct 145 ms 1904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 207 ms 5496 KB Output is correct
2 Correct 186 ms 5496 KB Output is correct
3 Execution timed out 1090 ms 5496 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1074 ms 5496 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 5496 KB Output is correct
2 Correct 113 ms 5496 KB Output is correct
3 Correct 43 ms 5740 KB Output is correct
4 Execution timed out 1068 ms 5740 KB Time limit exceeded