Submission #54898

# Submission time Handle Problem Language Result Execution time Memory
54898 2018-07-05T09:15:44 Z 강태규(#1507) Potemkin cycle (CEOI15_indcyc) C++11
70 / 100
1000 ms 5608 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];
bool visited[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;
            visited[i] = 0;
        }
        
        queue<int> q;
        visited[a] = 1;
        q.push(a);
        while (!q.empty()) {
            int x = q.front();
            q.pop();
            if (x == b) break;
            for (int i : edge[x]) {
                if (visited[i]) continue;
                visited[i] = 1;
                q.push(i);
            }
        }
        
        if (!visited[b]) continue;
        
        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:31: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:33: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);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 624 KB Output is correct
2 Correct 2 ms 624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 956 KB Output is correct
2 Correct 16 ms 1068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 165 ms 2016 KB Output is correct
2 Correct 12 ms 2016 KB Output is correct
3 Correct 7 ms 2016 KB Output is correct
4 Correct 65 ms 2016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2016 KB Output is correct
2 Correct 181 ms 2016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 5496 KB Output is correct
2 Correct 182 ms 5496 KB Output is correct
3 Execution timed out 1080 ms 5608 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 5608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1034 ms 5608 KB Time limit exceeded
2 Halted 0 ms 0 KB -