Submission #38055319


Source Code Expand

#include <bits/stdc++.h>
//#define st first
#define nd second
#define db double
#define re register
#define pb push_back
#define mk make_pair
#define int long long
#define ldb long double
#define pii pair<int, int>
#define ull unsigned long long
#define mst(a, b) memset(a, b, sizeof(a))
using namespace std;
const int N = 1e5 + 10;
inline int read()
{
  int s = 0, w = 1;
  char ch = getchar();
  while(ch < '0' || ch > '9') { if(ch == '-') w *= -1; ch = getchar(); }
  while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
int n;
string s[N], t[N];
map<string, int> mp;
vector<int> G[N << 1];
bool flag, vis[N << 1], Jud[N << 1];
inline void DFS(int u)
{
  vis[u] = true, Jud[u] = true;
  for(re int to : G[u]){
    if(Jud[to]) { flag = true; return; }
    if(!vis[to]) DFS(to);
    if(flag) return;
  }
  Jud[u] = false;
}
signed main()
{
  n = read();
  for(re int i = 1; i <= n; i++) cin >> s[i] >> t[i];
  for(re int i = 1; i <= n; i++) mp[s[i]] = i;
  for(re int i = 1; i <= n; i++){
    G[i].pb(i + n);
    if(mp.find(t[i]) != mp.end()) G[i + n].pb(mp[t[i]]);
  }
  for(re int i = 1; i <= n; i++){
    if(!vis[i]){
      DFS(i);
      if(flag) puts("No"), exit(0);
    }
  }
  puts("Yes");
  return 0;
}

Submission Info

Submission Time
Task D - Change Usernames
User Booksnow
Language C++ (GCC 9.2.1)
Score 400
Code Size 1298 Byte
Status AC
Exec Time 194 ms
Memory 38304 KiB

Compile Error

./Main.cpp: In function ‘void DFS(long long int)’:
./Main.cpp:31:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   31 |   for(re int to : G[u]){
      |              ^~
./Main.cpp: In function ‘int main()’:
./Main.cpp:41:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   41 |   for(re int i = 1; i <= n; i++) cin >> s[i] >> t[i];
      |              ^
./Main.cpp:42:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   42 |   for(re int i = 1; i <= n; i++) mp[s[i]] = i;
      |              ^
./Main.cpp:43:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   43 |   for(re int i = 1; i <= n; i++){
      |              ^
./Main.cpp:47:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   47 |   for(re int i = 1; i <= n; i++){
      |              ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 22
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 141 ms 25648 KiB
random_02.txt AC 137 ms 25656 KiB
random_03.txt AC 192 ms 34004 KiB
random_04.txt AC 187 ms 35380 KiB
random_05.txt AC 194 ms 38148 KiB
random_06.txt AC 187 ms 38304 KiB
random_07.txt AC 192 ms 35752 KiB
random_08.txt AC 189 ms 33720 KiB
random_09.txt AC 158 ms 28968 KiB
random_10.txt AC 172 ms 28688 KiB
random_11.txt AC 169 ms 28216 KiB
random_12.txt AC 161 ms 27900 KiB
random_13.txt AC 161 ms 27556 KiB
random_14.txt AC 171 ms 28860 KiB
random_15.txt AC 160 ms 28552 KiB
random_16.txt AC 163 ms 28060 KiB
random_17.txt AC 168 ms 27808 KiB
random_18.txt AC 163 ms 27600 KiB
random_19.txt AC 12 ms 14492 KiB
sample_01.txt AC 12 ms 14492 KiB
sample_02.txt AC 13 ms 14340 KiB
sample_03.txt AC 12 ms 14456 KiB