Submission #571676

# Submission time Handle Problem Language Result Execution time Memory
571676 2022-06-02T13:56:11 Z MODDI Monthly railway pass (LMIO18_menesinis_bilietas) C++14
0 / 100
3000 ms 48580 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define mp make_pair
#define pb push_back
using namespace std;
int n, m;
vi train[500010], bus[500010];
int main(){
	cin>>n>>m;
	for(int i = 0; i < m; i++){
		int a, b;
		char tip;
		cin>>a>>b>>tip;
		a--; b--;
		if(tip == 'T')
		{
			train[a].pb(b);
			train[b].pb(a);
		}
		else{
			bus[a].pb(b);
			bus[b].pb(a);
		}
	}
	int rez =0;
	for(int i = 0; i < n; i++){
		queue<pii> q;
		q.push(mp(i, 0));
		bool vis[n];
		memset(vis, false, sizeof(vis));
		vis[i] = true;
		set<int> city;
		while(!q.empty()){
			int at = q.front().first;
			int take = q.front().second;
			city.insert(at);
			q.pop();
			for(auto next : train[at]){
				if(!vis[next]){
					vis[next] = true;
					q.push(mp(next, take));
				}
			}
			if(take == 0){
				for(auto next : bus[at]){
					if(!vis[next]){
						vis[next] = true;
						q.push(mp(next, 1));
					}
				}
			}
		}
		if(city.size() == n){
			rez++;
		}
	}
	cout<<rez<<endl;
}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:57:18: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |   if(city.size() == n){
      |      ~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 3068 ms 48580 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3058 ms 24148 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 15 ms 23772 KB Output is correct
4 Correct 25 ms 23892 KB Output is correct
5 Incorrect 39 ms 24048 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 15 ms 23772 KB Output is correct
4 Correct 25 ms 23892 KB Output is correct
5 Incorrect 39 ms 24048 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 15 ms 23772 KB Output is correct
4 Correct 25 ms 23892 KB Output is correct
5 Incorrect 39 ms 24048 KB Output isn't correct
6 Halted 0 ms 0 KB -