Submission #846243

# Submission time Handle Problem Language Result Execution time Memory
846243 2023-09-07T12:52:18 Z vjudge1 KOVANICE (COI15_kovanice) C++
0 / 100
56 ms 76624 KB
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long a,b,c,d;
	cin>>a>>b>>c;
	string kel;
	long long arr[b + 5];
	long long vis[b + 5];
	vector <long long> es[b + 5];
	priority_queue < pair <long long,long long> > que;
	vector <long long> ana;
	memset(arr,-1,sizeof(arr));
	string str[c + 5];
	vector <pair <long long,long long> > adj[b + 5];
	d=0;
	for(long long i=0;b>i;i++){
		es[i].push_back(i);
	}
	for(long long i=0;c>i;i++){
		cin>>kel;
		if(kel[1] == '='){
			adj[kel[2] - '1'].push_back(make_pair(0,kel[0] - '1'));
			adj[kel[0] - '1'].push_back(make_pair(0,kel[2] - '1'));
		}
		else{
			if(arr[kel[2] - '1'] == -1){
				arr[kel[2] - '1'] = 0;
			}
			if(arr[kel[0] - '1'] == -1){
				arr[kel[0] - '1'] = 0;
			}
			adj[kel[2] - '1'].push_back(make_pair(1,kel[0] - '1'));
			arr[kel[0] - '1']++;
		}
	}
	for(long long i=0;b>i;i++){
		if(arr[i] == 0){
			ana.push_back(i);
		}
	}
	memset(arr,-1,sizeof(arr));
	memset(vis,0,sizeof(vis));
	for(long long i=0;ana.size()>i;i++){
		que.push(make_pair(-1,ana[i]));	
		arr[ana[i]] = 0;
	}
	long long pivot,enb;
	enb=0;
	while(que.size()){
		pivot = que.top().second;
		que.pop();
		if(vis[pivot] == 0){
			vis[pivot] = 1;
			for(long long i=0;adj[pivot].size()>i;i++){
				if(vis[adj[pivot][i].first] == 0 ){
					arr[adj[pivot][i].second] = arr[pivot] + adj[pivot][i].first;
				if(enb < (arr[pivot] + adj[pivot][i].first)){
					enb = arr[pivot] + adj[pivot][i].first;
				}
				que.push(make_pair((adj[pivot][i].first),(adj[pivot][i].second)));


				}
			}
		}
	}
	if(a != (enb + 1)){
		for(long long i=0;b>i;i++){
			cout<<"?\n";
		}
	}
	else{
		for(long long i=0;b>i;i++){
			if(arr[i] != -1){
				cout<<"K"<<a - arr[i]<<"\n";
			}
			else{
				cout<<"?\n";
			}
		}
	}




	
}

Compilation message

kovanice.cpp: In function 'int main()':
kovanice.cpp:45:30: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   45 |  for(long long i=0;ana.size()>i;i++){
      |                    ~~~~~~~~~~^~
kovanice.cpp:56:39: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   56 |    for(long long i=0;adj[pivot].size()>i;i++){
      |                      ~~~~~~~~~~~~~~~~~^~
kovanice.cpp:6:18: warning: variable 'd' set but not used [-Wunused-but-set-variable]
    6 |  long long a,b,c,d;
      |                  ^
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 33 ms 44880 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 7000 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 56 ms 76624 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -