답안 #956197

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956197 2024-04-01T09:51:14 Z Trisanu_Das 통행료 (APIO13_toll) C++17
16 / 100
1 ms 348 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
 
using namespace std;
#define MAX_N 100000
#define MAX_M 300000
typedef long long ll;
 
int N, M, K;
struct EDGE{
	EDGE (int x, int y, int z) : x(x), y(y), z(z) {}
	int x, y, z;
	bool operator <(const EDGE &a)const{
		return z<a.z;
	}
};
vector<EDGE> edge;
struct EDGE2{
	EDGE2 (int x, int y) : x(x), y(y) {}
	int x, y;
};
vector<EDGE2> edge2;
vector<int> P;
struct S{
	S (int idx, int data) : idx(idx), data(data) {}
	int idx, data;
};
//vector<S> gp[MAX_N+1];
int g[MAX_N+1];
 
void init(){
	for(int i=1; i<=N; i++)	g[i] = i;
}
 
int find_g(int x){
	if(x==g[x])	return x;
	return g[x] = find_g(g[x]);
}
 
void union_g(int x, int y){
	x = find_g(x); y = find_g(y);
	g[x] = y;
}
 
bool use[MAX_M+1];
 
void solve1(){
	int idx = -1;
	init();
	for(int i=0; i<edge.size(); i++){
		if(find_g(edge[i].x)==find_g(edge[i].y))	continue;
		union_g(edge[i].x, edge[i].y);
		use[i] = true;
		if(idx==-1 && find_g(edge2[0].x)==find_g(edge2[0].y)){
			idx = i;
			use[i] = false;
		}
	}
	//cout<<idx<<endl;
	init();
	for(int i=0; i<edge.size(); i++){
		if(!use[i])	continue;
		union_g(edge[i].x, edge[i].y);
	}
	ll ans=0;
	for(int i=1; i<=N; i++){
		if(find_g(i)==find_g(1))	continue;
		ans += (ll)P[i];
	}
	ans *= (ll)edge[idx].z;
	printf("%lld", ans);
}
 
int main(){
	scanf("%d%d%d", &N, &M, &K);
	for(int i=0; i<M; i++){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		edge.push_back({a, b, c});
	}sort(edge.begin(), edge.end());
	for(int i=0; i<K; i++){
		int a, b;
		scanf("%d%d", &a, &b); edge2.push_back({a, b});
	}P.push_back(0);
	for(int i=1; i<=N; i++){
		int a; scanf("%d", &a); P.push_back(a);
	}
	if(N<=10 && M<=20 && K==1){
		solve1();
	}
	return 0;
}

Compilation message

toll.cpp: In function 'void solve1()':
toll.cpp:52:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<EDGE>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for(int i=0; i<edge.size(); i++){
      |               ~^~~~~~~~~~~~
toll.cpp:63:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<EDGE>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |  for(int i=0; i<edge.size(); i++){
      |               ~^~~~~~~~~~~~
toll.cpp: In function 'int main()':
toll.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |  scanf("%d%d%d", &N, &M, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
toll.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |   scanf("%d%d%d", &a, &b, &c);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
toll.cpp:85:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |   scanf("%d%d", &a, &b); edge2.push_back({a, b});
      |   ~~~~~^~~~~~~~~~~~~~~~
toll.cpp:88:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |   int a; scanf("%d", &a); P.push_back(a);
      |          ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -