QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#524656#6560. Broken Minimum Spanning Treeamirreza#WA 0ms3820kbC++203.0kb2024-08-19 22:36:432024-08-19 22:36:45

Judging History

你现在查看的是最新测评结果

  • [2024-08-19 22:36:45]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3820kb
  • [2024-08-19 22:36:43]
  • 提交

answer


// ki bood ke goft Ghatinga?

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pii,int> ppiii;

// vectors and Sets:
#define vc vector
#define pb push_back
#define all(c) (c).begin(), (c).end()

// pairs
#define mp make_pair
#define fr first
#define sc second

// execution time check and Debug
#define StartEX clock_t startExeTime = clock();
#define EndEX clock_t endExeTime = clock();
#define ExTime cerr << "\nTotal Execution Time is: " << double(-double(startExeTime)+double(endExeTime)) / CLOCKS_PER_SEC;
#define debug(x) cerr << #x << " : " << x << '\n'
#define endl "\n"

// time optimization
#define Heh ios::sync_with_stdio(false);cin.tie(0);
#define Bah ios::sync_with_stdio(false);
#pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

// useful functions
ll pw(ll a,ll b){
  ll ret = 1;
  ll mul = a;
  while(b > 0){
	if(b&1)
	  ret = (ret * mul);
	mul = (mul * mul);
	b >>= 1;
  }
  return ret;
}
ll pw(ll a,ll b,ll mod){
  ll ret = 1;
  ll mul = a;
  while(b > 0){
	if(b&1)
	  ret = (ret * mul) % mod;
	mul = (mul * mul) % mod;
	b >>= 1;
  }
  return ret;
}

ll to_int(string s){
  ll ret = 0;
  for(int i = 0 ; i < (int)s.size() ; i++) ret = 10 * ret + s[i] - '0';
  return ret;
}

bool deq(ld a , ld b){return (abs(a-b) < 0.000001);} // 10 ^ -6

const int MAXM = 3e3 + 33;

int n , m;

int par[MAXM] , rnk[MAXM];
int get(int v){return par[v] = (par[v] == v ? v : get(par[v]));}
void uni(int a , int b){
  a = get(a) , b = get(b);
  if(a == b) return;
  if(rnk[a] < rnk[b]) swap(a , b);
  par[b] = a;
  rnk[a] += (rnk[a] == rnk[b]);
}

pair<pii,pii> eds[MAXM] , seds[MAXM];

int can[MAXM];

vc<pii> ans;

bool cmp(pair<pii,pii> a , pair<pii,pii> b){
  return a.sc < b.sc;
}

int main()
{
  cin >> n >> m;
  for(int i = 0 ; i < m ; i++){
    int u , v , w;
    cin >> u >> v >> w;
    u-- , v--;
    eds[i] = {{u , v} , {w , i}};
    seds[i] = eds[i];
  }
  sort(seds , seds + m , cmp);

  for(int i = 0 ; i < n ; i++) par[i] = i , rnk[i] = 0;
  for(int i = 0 ; i < m ; i++){
    if(i == 0 or seds[i].sc.fr != seds[i-1].sc.fr){
      for(int j = i ; j < m and seds[j].sc.fr == seds[i].sc.fr ; j++){
	can[seds[j].sc.sc] = (get(seds[j].fr.fr) == get(seds[j].fr.sc) ? 0 : 1);
      }
    }
    uni(seds[i].fr.fr , seds[i].fr.sc);
  }

  vc<pii> sct;
  for(int i = 0 ; i < n-1 ; i++){
    if(can[i] == 0){
      for(int j = 0 ; j < n ; j++) par[j] = j , rnk[j] = 0;
      for(auto [u , v] : sct) uni(u , v);
      for(int j = i+1 ; j < n-1 ; j++) uni(eds[j].fr.fr , eds[j].fr.sc);
      
      for(int j = 0 ; j < m ; j++){
	if(get(seds[j].fr.fr) != get(seds[j].fr.sc)){
	  ans.pb({i , seds[j].sc.sc});
	  sct.pb({seds[j].fr.fr , seds[j].fr.sc});
	  break;
	}
      }
    }
    else sct.pb({eds[i].fr.fr , eds[i].fr.sc});
  }

  cout << ans.size() << endl;
  for(auto [a , b] : ans) cout << a+1 << " " << b+1 << endl;
  
}

// ki seda kard Patinga?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

input:

4 4
1 2 10
2 3 3
3 4 1
1 4 4

output:

1
1 4

result:

ok correct!

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3820kb

input:

6 8
1 2 10
2 3 10
3 4 10
4 5 10
5 6 10
6 1 10
1 3 1
4 6 1

output:

0

result:

FAIL participant's MST is better than jury!