답안 #896996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
896996 2024-01-02T12:02:03 Z Litusiano 게임 (APIO22_game) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
#include "game.h"


int k1,n1;

vector<vector<int>> G,Grev, DAG;
vector<int> top,used,scc;
int act = 0;
void dfs(int u){
	if(used[u]) return;
	used[u] = 1;
	// cerr<<"START "<<u<<endl;
	for(int v : G[u]) dfs(v);
	// cerr<<"END "<<u<<endl;
	top.push_back(u);
}

void dfs1(int u){
	if(used[u]) return;
	used[u] = 1;
	for(int v : Grev[u]){
		dfs1(v);
	}
	scc[u] = act;
}

void init(int n, int k) {
	k1 = k; n1 = n;
	G.assign(n,vector<int>());
	Grev = G;
	// cerr<<"HERE "<<n<<" "<<k<<endl;
	for(int i = 0; i<=k-2; i++){
		G[i].push_back(i+1);
		Grev[i+1].push_back(i);
	}
}

int add_teleporter(int u, int v) {

	// if(scc.size() && scc[u] == scc[v] && scc[u] > -1) return 0;
	if(u == v){
		if(u < k1) return 1;
		return 0;
	}
	G[u].push_back(v);
	Grev[v].push_back(u);
	used.assign(n1,0);
	scc.assign(n1,-1);
	top.clear();
	// cerr<<"STARTING DFS OF EDGE "<<u<<" "<<v<<endl;

	for(int i = 0; i<n1; i++) dfs(i);
	// cerr<<"TOP"<<endl;
	// for(int i : top) cerr<<i<<" ";
		// cerr<<"END TOP"<<endl;
	used.assign(n1,0);
	act = 0;
	for(int i = top.size()-1; i>=0; i--){
		if(!used[top[i]]) act++, scc[top[i]] = act, dfs1(top[i]);
	}
	set<int> hv; 
	for(int i = 0; i<k1; i++){
		hv.insert(scc[i]);
	}
	//  cerr<<"STARTING SCC OF EDGE: "<<u<<" "<<v<<endl;
	// for(int i = 0; i<n1; i++){
	// 	cerr<<"SCC: "<<i<<" "<<scc[i]<<endl;
	// }
	// cerr<<endl;
	if(hv.size() < k1) return 1;

	for(int i = k1; i<n1; i++){
		if(hv.count(scc[i])) return 1;
	}
  return 0;
}


int read_int() {
  int x;
  if (scanf("%d", &x) != 1) {
    fprintf(stderr	, "Error while reading input\n");
    exit(1);
  }
  return x;
}


int main() {
  int N = read_int();
  int M = read_int();
  int K = read_int();
  std::vector<int> u(M), v(M);
  for (int i = 0; i < M; ++i) {
    u[i] = read_int();
    v[i] = read_int();
  }

  init(N, K);
  int i;
  for (i = 0; i < M; ++i) {
    int answer = add_teleporter(u[i], v[i]);
    if (answer != 0 && answer != 1) {
      i = -1;
      break;
    } else if (answer == 1) {
      break;
    }
  }
  printf("ANS %d\n", i);
  return 0;
}

Compilation message

game.cpp: In function 'int add_teleporter(int, int)':
game.cpp:72:15: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   72 |  if(hv.size() < k1) return 1;
      |     ~~~~~~~~~~^~~~
/usr/bin/ld: /tmp/cc9mtSIZ.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccX8ODqW.o:game.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status