답안 #542165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
542165 2022-03-25T15:07:19 Z rainliofficial Potemkin cycle (CEOI15_indcyc) Java 11
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define f first
#define s second

struct edge{
    int from, to;
};

const int MAXN = 1005, MAXR = 2e5+5;
edge allEdges[MAXR];
vector<int> edgeGraph[MAXR], cycle;
int connected[MAXN][MAXN];
bool vis[MAXN][MAXN], on_stack[MAXR], vis2[MAXR];
int n, r;

void dfs(int at, int pv){
    vis[at][pv] = true; 
    // connect all possible edges
    for (int i=0; i<n; i++){
        if (pv != n && i != at && i != pv && connected[at][i] && !connected[i][pv]){
            assert(connected[pv][at] != 0);
            edgeGraph[connected[pv][at]].push_back(connected[at][i]);
        }
    }
    for (int i=0; i<n; i++){
        if (connected[at][i] && !vis[i][at]){
            dfs(i, at);
        }
    }
}

bool dfs2(int at) {
	vis2[at] = on_stack[at] = true;
	for (int u : edgeGraph[at]) {
		if(on_stack[u]) {
			cycle.push_back(at); // start cycle
			on_stack[at] = on_stack[u] = false;
			return true;
		}else if(!vis2[u]) {
			if(dfs2(u)) { // continue cycle
				if(on_stack[at]) {
					cycle.push_back(at);
					on_stack[at] = false;
					return true;
				} else { // found u again
					cycle.push_back(at);
					return false;
				}
			}
			if(!cycle.empty()) // finished with cycle
				return false;
		}
	}
	on_stack[at] = false;
	return false;
}
int main(){
    cin.tie(0); ios_base::sync_with_stdio(0); 
    // freopen("file.in", "r", stdin);
    // freopen("file.out", "w", stdout);
    cin >> n >> r;
    for (int i=0; i<r; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        allEdges[2*i+1] = {a, b};
        allEdges[2*i+2] = {b, a};
        connected[a][b] = 2*i+1;
        connected[b][a] = 2*i+2;
    }
    dfs(0, n);
    for (int i=1; i<=2*r; i++){
        if (!vis2[i]){
            dfs2(i);
        }
        if (!cycle.empty()) break;
    }
    if (cycle.empty()){
        cout << "no" << "\n";
        return 0;
    }
    // reverse(cycle.begin(), cycle.end());
    vector<int> ans;
    assert(sz(cycle) > 3);
    for (int i=0; i<sz(cycle)-1; i++){
        if (i == 0){
            cout << allEdges[cycle[i]].from+1 << " ";
        }
        cout << allEdges[cycle[i]].to+1 << " ";
    }
}

Compilation message

indcyc.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
indcyc.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
indcyc.java:3: error: illegal character: '#'
#define ll long long
^
indcyc.java:3: error: class, interface, or enum expected
#define ll long long
        ^
indcyc.java:4: error: illegal character: '#'
#define pii pair<int, int>
^
indcyc.java:5: error: illegal character: '#'
#define sz(x) (int)x.size()
^
indcyc.java:6: error: illegal character: '#'
#define f first
^
indcyc.java:7: error: illegal character: '#'
#define s second
^
indcyc.java:11: error: class, interface, or enum expected
};
^
indcyc.java:13: error: class, interface, or enum expected
const int MAXN = 1005, MAXR = 2e5+5;
^
indcyc.java:14: error: class, interface, or enum expected
edge allEdges[MAXR];
^
indcyc.java:15: error: class, interface, or enum expected
vector<int> edgeGraph[MAXR], cycle;
^
indcyc.java:16: error: class, interface, or enum expected
int connected[MAXN][MAXN];
^
indcyc.java:17: error: class, interface, or enum expected
bool vis[MAXN][MAXN], on_stack[MAXR], vis2[MAXR];
^
indcyc.java:18: error: class, interface, or enum expected
int n, r;
^
indcyc.java:20: error: class, interface, or enum expected
void dfs(int at, int pv){
^
indcyc.java:23: error: class, interface, or enum expected
    for (int i=0; i<n; i++){
    ^
indcyc.java:23: error: class, interface, or enum expected
    for (int i=0; i<n; i++){
                  ^
indcyc.java:23: error: class, interface, or enum expected
    for (int i=0; i<n; i++){
                       ^
indcyc.java:26: error: class, interface, or enum expected
            edgeGraph[connected[pv][at]].push_back(connected[at][i]);
            ^
indcyc.java:27: error: class, interface, or enum expected
        }
        ^
indcyc.java:29: error: class, interface, or enum expected
    for (int i=0; i<n; i++){
                  ^
indcyc.java:29: error: class, interface, or enum expected
    for (int i=0; i<n; i++){
                       ^
indcyc.java:32: error: class, interface, or enum expected
        }
        ^
indcyc.java:38: error: class, interface, or enum expected
	for (int u : edgeGraph[at]) {
	^
indcyc.java:41: error: class, interface, or enum expected
			on_stack[at] = on_stack[u] = false;
			^
indcyc.java:42: error: class, interface, or enum expected
			return true;
			^
indcyc.java:43: error: class, interface, or enum expected
		}else if(!vis2[u]) {
		^
indcyc.java:47: error: class, interface, or enum expected
					on_stack[at] = false;
					^
indcyc.java:48: error: class, interface, or enum expected
					return true;
					^
indcyc.java:49: error: class, interface, or enum expected
				} else { // found u again
				^
indcyc.java:51: error: class, interface, or enum expected
					return false;
					^
indcyc.java:52: error: class, interface, or enum expected
				}
				^
indcyc.java:56: error: class, interface, or enum expected
		}
		^
indcyc.java:59: error: class, interface, or enum expected
	return false;
	^
indcyc.java:60: error: class, interface, or enum expected
}
^
indcyc.java:62: error: class, interface, or enum expected
    cin.tie(0); ios_base::sync_with_stdio(0); 
                ^
indcyc.java:65: error: class, interface, or enum expected
    cin >> n >> r;
    ^
indcyc.java:66: error: class, interface, or enum expected
    for (int i=0; i<r; i++){
    ^
indcyc.java:66: error: class, interface, or enum expected
    for (int i=0; i<r; i++){
                  ^
indcyc.java:66: error: class, interface, or enum expected
    for (int i=0; i<r; i++){
                       ^
indcyc.java:68: error: class, interface, or enum expected
        cin >> a >> b;
        ^
indcyc.java:69: error: class, interface, or enum expected
        a--; b--;
        ^
indcyc.java:69: error: class, interface, or enum expected
        a--; b--;
             ^
indcyc.java:70: error: class, interface, or enum expected
        allEdges[2*i+1] = {a, b};
        ^
indcyc.java:71: error: class, interface, or enum expected
        allEdges[2*i+2] = {b, a};
        ^
indcyc.java:72: error: class, interface, or enum expected
        connected[a][b] = 2*i+1;
        ^
indcyc.java:73: error: class, interface, or enum expected
        connected[b][a] = 2*i+2;
        ^
indcyc.java:74: error: class, interface, or enum expected
    }
    ^
indcyc.java:76: error: class, interface, or enum expected
    for (int i=1; i<=2*r; i++){
    ^
indcyc.java:76: error: class, interface, or enum expected
    for (int i=1; i<=2*r; i++){
                  ^
indcyc.java:76: error: class, interface, or enum expected
    for (int i=1; i<=2*r; i++){
                          ^
indcyc.java:79: error: class, interface, or enum expected
        }
        ^
indcyc.java:81: error: class, interface, or enum expected
    }
    ^
indcyc.java:84: error: class, interface, or enum expected
        return 0;
        ^
indcyc.java:85: error: class, interface, or enum expected
    }
    ^
indcyc.java:88: error: as of release 1.4, 'assert' is a keyword, and may not be used as an identifier
    assert(sz(cycle) > 3);
    ^
indcyc.java:89: error: class, interface, or enum expected
    for (int i=0; i<sz(cycle)-1; i++){
    ^
indcyc.java:89: error: class, interface, or enum expected
    for (int i=0; i<sz(cycle)-1; i++){
                  ^
indcyc.java:89: error: class, interface, or enum expected
    for (int i=0; i<sz(cycle)-1; i++){
                                 ^
indcyc.java:92: error: class, interface, or enum expected
        }
        ^
indcyc.java:94: error: class, interface, or enum expected
    }
    ^
62 errors