Submission #920965

# Submission time Handle Problem Language Result Execution time Memory
920965 2024-02-03T08:25:58 Z WongYiKai Monthly railway pass (LMIO18_menesinis_bilietas) C++14
16 / 100
314 ms 83384 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll visited[600000];
ll type[600000];
ll c=1;
ll sets[600000];

vector<ll> adj[600000],adj2[600000];

void dfs(ll vertex){
	visited[vertex] = 1;
	type[vertex] = c;
	sets[c]++;
	for (auto item:adj[vertex]){
		if (visited[item]==0){
			dfs(item);
		}
	}
}
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n,m;
	cin >> n >> m;
	for (int i=0;i<m;i++){
		ll a,b;
		char t;
		cin >> a >> b >> t;
		if (t=='T'){
			adj[a].push_back(b);
			adj[b].push_back(a);
		}
		else {
			adj2[a].push_back(b);
			adj2[b].push_back(a);
		}
	}
	for (int i=1;i<=n;i++){
		if (visited[i]==0){
			dfs(i);
			c++;
		}
	}
	vector<ll> con[c+5];
	for (int i=1;i<=n;i++){
		for (auto item:adj2[i]){
			if (type[i]!=type[item]){
				con[type[i]].push_back(type[item]);
			}
		}
	}
	c--;
	ll total=0;
	for (int i=1;i<=c;i++){
		//cout << con[i].size() << "\n";
		if (con[i].size() == c-1) total += sets[i];
	}
	cout << total;
}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:57:21: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   57 |   if (con[i].size() == c-1) total += sets[i];
      |       ~~~~~~~~~~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 314 ms 60736 KB Output is correct
2 Correct 8 ms 31184 KB Output is correct
3 Correct 8 ms 31320 KB Output is correct
4 Correct 21 ms 52060 KB Output is correct
5 Correct 8 ms 31576 KB Output is correct
6 Correct 42 ms 38224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 52060 KB Output is correct
2 Correct 8 ms 31576 KB Output is correct
3 Correct 8 ms 31324 KB Output is correct
4 Correct 8 ms 31324 KB Output is correct
5 Correct 9 ms 31664 KB Output is correct
6 Correct 91 ms 47792 KB Output is correct
7 Correct 195 ms 83384 KB Output is correct
8 Correct 12 ms 32860 KB Output is correct
9 Correct 16 ms 33348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 31184 KB Output is correct
2 Correct 8 ms 31320 KB Output is correct
3 Correct 8 ms 31324 KB Output is correct
4 Correct 8 ms 31324 KB Output is correct
5 Correct 9 ms 31664 KB Output is correct
6 Incorrect 7 ms 31324 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 31324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 31324 KB Output isn't correct
2 Halted 0 ms 0 KB -