Submission #95137

# Submission time Handle Problem Language Result Execution time Memory
95137 2019-01-27T14:54:14 Z Retro3014 Teleporters (IOI08_teleporters) C++17
0 / 100
485 ms 66560 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>

#define MAX_X 2000000
using namespace std;
typedef long long ll;
int N, M;
int g[MAX_X+1];
int r[MAX_X+1];
bool vst[MAX_X+1];

vector<int> cycle;
int ans;

void dfs(int x, ll y){
	if(vst[x]){
		cycle.push_back(y);
		return;
	}
	vst[x] = true;
	if(x==MAX_X){
		ans+=y;
		return;
	}
	if(r[x]!=x+1)	dfs(r[x], y+1);
	else	dfs(r[x], y+1);
}

int main(){
	scanf("%d%d", &N, &M);
	for(int i=0; i<MAX_X; i++)	r[i] = i+1;
	for(int i=0; i<N; i++){
		int a, b; scanf("%d%d", &a, &b);
		r[a-1] = b; r[b-1] = a;
	}
	for(int i=0; i<MAX_X; i++){
		if(vst[i])	continue;
		dfs(i, 0);
	}
	sort(cycle.begin(), cycle.end());
	while(M--){
		if(cycle.empty()){
			cycle.push_back(1);
			ans++;
		}else{
			ans+=2+cycle.back();
			cycle.pop_back();
		}
	}
	printf("%d", ans);
	return 0;
}

Compilation message

teleporters.cpp: In function 'int main()':
teleporters.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
teleporters.cpp:35:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a, b; scanf("%d%d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 70 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 65 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 61 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 65 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 64 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 66 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 67 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 61 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 64 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 64 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 63 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 61 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 67 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 69 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 67 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Incorrect 105 ms 57936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 144 ms 35692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 316 ms 19052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 456 ms 23420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 485 ms 29240 KB Output isn't correct
2 Halted 0 ms 0 KB -