提出 #44564855


ソースコード 拡げる

#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=2e5+5;
int zalatwione=0;
bool O[MAX];
bool used[MAX];
char s[MAX];
int p[MAX];
vector<pair<int,int>>P[MAX];
char color[MAX];
int Find(int u){
  if (p[u]!=u)p[u]=Find(p[u]);
  return p[u];
}
void Union(int u,int v){
  assert(Find(u)!=Find(v));
  p[Find(u)]=Find(v);
}
int32_t main()
{
  BOOST;
  int n,m;
  cin>>n>>m;
  for (int i=1;i<=m;i++){
    int a,b;
    char c;
    cin>>a>>b>>c;
    color[i]=c;
    P[a].pb(mp(b,i));
    P[b].pb(mp(a,i));
  }
  for (int i=1;i<=n;i++)p[i]=i;
  for (int i=1;i<=n;i++)cin>>s[i];
  for (int i=1;i<=n;i++){
    for (auto it:P[i]){
      if (color[it.nd]==s[i] && color[it.nd]==s[it.st]){
        int u=i;
        int v=it.st;
        if (Find(u)!=Find(v)){
          Union(u,v);
          assert(!used[it.nd]);
          used[it.nd]=true;
          O[u]=true,O[v]=true;
        }
      }
    }
  }
  queue<int>q;
  for (int i=1;i<=n;i++){
    if (O[i]){
      q.push(i);
    }
  }
  while (!q.empty()){
    int u=q.front();
    q.pop();
    for (auto it:P[u]){
      if (O[it.st])continue;
     // cout<<"KOLEJKA "<<u<<" "<<it.st<<" "<<O[it.st]<<" "<<s[it.st]<<" "<<color[it.nd]<<"\n";
      if (!O[it.st] && color[it.nd]==s[it.st] && Find(u)!=Find(it.st)){
        O[it.st]=true;
        used[it.nd]=true;
        Union(u,it.st);
        q.push(it.st);
      }
    }
  }

  for (int i=1;i<=n;i++){
    if (!O[i]){
      cout<<"No";
      return 0;
    }
  }
  for (int i=1;i<=n;i++){
    for (auto it:P[i]){
      int u=i;
      int v=it.st;
      if (Find(u)!=Find(v)){
        Union(u,v);
        used[it.nd]=true;
      }
    }
  }
  cout<<"Yes\n";
  vi ans;
  for (int i=1;i<=m;i++){
    if (used[i])ans.pb(i);
  }
  assert(sz(ans)==n-1);
  for (auto it:ans)cout<<it<<" ";
  return 0;
}

提出情報

提出日時
問題 B - Red and Blue Spanning Tree
ユーザ michao
言語 C++ 20 (gcc 12.2)
得点 600
コード長 2253 Byte
結果 AC
実行時間 103 ms
メモリ 25168 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 4
AC × 77
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 01_small_08.txt, 01_small_09.txt, 01_small_10.txt, 01_small_11.txt, 01_small_12.txt, 01_small_13.txt, 01_small_14.txt, 01_small_15.txt, 01_small_16.txt, 01_small_17.txt, 02_dense_00.txt, 02_dense_01.txt, 02_dense_02.txt, 02_dense_03.txt, 02_dense_04.txt, 02_dense_05.txt, 02_dense_06.txt, 02_dense_07.txt, 02_dense_08.txt, 02_dense_09.txt, 02_dense_10.txt, 02_dense_11.txt, 03_rnd_00.txt, 03_rnd_01.txt, 03_rnd_02.txt, 03_rnd_03.txt, 03_rnd_04.txt, 03_rnd_05.txt, 03_rnd_06.txt, 03_rnd_07.txt, 04_same_00.txt, 04_same_01.txt, 04_same_02.txt, 04_same_03.txt, 04_same_04.txt, 04_same_05.txt, 04_same_06.txt, 04_same_07.txt, 05_star_00.txt, 05_star_01.txt, 05_star_02.txt, 05_star_03.txt, 05_star_04.txt, 06_cycle_00.txt, 06_cycle_01.txt, 06_cycle_02.txt, 06_cycle_03.txt, 06_cycle_04.txt, 06_cycle_05.txt, 06_cycle_06.txt, 07_hand_00.txt, 07_hand_01.txt, 07_hand_02.txt, 07_hand_03.txt, 07_hand_04.txt, 07_hand_05.txt, 07_hand_06.txt, 07_hand_07.txt, 07_hand_08.txt, 07_hand_09.txt, 07_hand_10.txt, 07_hand_11.txt, 07_hand_12.txt, 07_hand_13.txt, 07_hand_14.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 2 ms 3444 KiB
00_sample_01.txt AC 2 ms 3416 KiB
00_sample_02.txt AC 2 ms 3548 KiB
00_sample_03.txt AC 2 ms 3636 KiB
01_small_00.txt AC 2 ms 3560 KiB
01_small_01.txt AC 2 ms 3436 KiB
01_small_02.txt AC 2 ms 3420 KiB
01_small_03.txt AC 2 ms 3408 KiB
01_small_04.txt AC 2 ms 3452 KiB
01_small_05.txt AC 1 ms 3424 KiB
01_small_06.txt AC 2 ms 3496 KiB
01_small_07.txt AC 2 ms 3540 KiB
01_small_08.txt AC 2 ms 3464 KiB
01_small_09.txt AC 2 ms 3488 KiB
01_small_10.txt AC 1 ms 3440 KiB
01_small_11.txt AC 2 ms 3488 KiB
01_small_12.txt AC 2 ms 3504 KiB
01_small_13.txt AC 1 ms 3384 KiB
01_small_14.txt AC 2 ms 3560 KiB
01_small_15.txt AC 2 ms 3472 KiB
01_small_16.txt AC 2 ms 3408 KiB
01_small_17.txt AC 2 ms 3508 KiB
02_dense_00.txt AC 14 ms 8680 KiB
02_dense_01.txt AC 18 ms 9544 KiB
02_dense_02.txt AC 14 ms 8584 KiB
02_dense_03.txt AC 16 ms 9488 KiB
02_dense_04.txt AC 14 ms 8476 KiB
02_dense_05.txt AC 23 ms 10900 KiB
02_dense_06.txt AC 12 ms 7096 KiB
02_dense_07.txt AC 8 ms 6224 KiB
02_dense_08.txt AC 12 ms 7204 KiB
02_dense_09.txt AC 10 ms 6580 KiB
02_dense_10.txt AC 9 ms 6516 KiB
02_dense_11.txt AC 11 ms 6892 KiB
03_rnd_00.txt AC 60 ms 19272 KiB
03_rnd_01.txt AC 23 ms 9224 KiB
03_rnd_02.txt AC 42 ms 15232 KiB
03_rnd_03.txt AC 80 ms 21140 KiB
03_rnd_04.txt AC 62 ms 15996 KiB
03_rnd_05.txt AC 48 ms 13580 KiB
03_rnd_06.txt AC 49 ms 14308 KiB
03_rnd_07.txt AC 69 ms 17700 KiB
04_same_00.txt AC 60 ms 18600 KiB
04_same_01.txt AC 62 ms 16968 KiB
04_same_02.txt AC 78 ms 22732 KiB
04_same_03.txt AC 40 ms 12580 KiB
04_same_04.txt AC 48 ms 18856 KiB
04_same_05.txt AC 56 ms 19024 KiB
04_same_06.txt AC 38 ms 15764 KiB
04_same_07.txt AC 49 ms 18852 KiB
05_star_00.txt AC 66 ms 24844 KiB
05_star_01.txt AC 66 ms 24832 KiB
05_star_02.txt AC 67 ms 25168 KiB
05_star_03.txt AC 66 ms 24324 KiB
05_star_04.txt AC 64 ms 24836 KiB
06_cycle_00.txt AC 84 ms 23552 KiB
06_cycle_01.txt AC 85 ms 23536 KiB
06_cycle_02.txt AC 89 ms 23732 KiB
06_cycle_03.txt AC 88 ms 24396 KiB
06_cycle_04.txt AC 103 ms 24736 KiB
06_cycle_05.txt AC 64 ms 17368 KiB
06_cycle_06.txt AC 68 ms 17156 KiB
07_hand_00.txt AC 50 ms 16560 KiB
07_hand_01.txt AC 51 ms 16612 KiB
07_hand_02.txt AC 36 ms 14528 KiB
07_hand_03.txt AC 39 ms 14484 KiB
07_hand_04.txt AC 60 ms 21052 KiB
07_hand_05.txt AC 61 ms 22284 KiB
07_hand_06.txt AC 52 ms 17852 KiB
07_hand_07.txt AC 67 ms 20536 KiB
07_hand_08.txt AC 74 ms 21676 KiB
07_hand_09.txt AC 79 ms 22060 KiB
07_hand_10.txt AC 90 ms 22488 KiB
07_hand_11.txt AC 87 ms 22620 KiB
07_hand_12.txt AC 85 ms 22604 KiB
07_hand_13.txt AC 72 ms 21368 KiB
07_hand_14.txt AC 71 ms 21200 KiB