提出 #30490718


ソースコード 拡げる

#include<bits/stdc++.h>
const double pi = acos(-1.0);
using namespace std;
//using namespace __gnu_pbds;
#define   endl    '\n'
#define   sl(n)     scanf("%lld",&n)
#define   mp      make_pair
#define   pb      push_back
#define   ppb     pop_back
#define   fi      first
#define   se      second
#define   ll      long long
#define   ull     unsigned long long
#define   ld      long double
#define   pii     pair<int, int>
#define   f(i,a,b)  for(ll i = (ll)(a); i < (ll)(b); i++)
#define   rf(i,a,b)   for(ll i = (ll)(a); i > (ll)(b); i--)
#define   ms(a,b)   memset((a),(b),sizeof(a))
#define   abs(x)    ((x<0)?(-(x)):(x))
#define   MAX     200005
#define   inf     LLONG_MAX
#define   ninf    LLONG_MIN
#define   MIN     INT_MIN
#define   yeet    return 0;
#define tihs if(fopen("input.txt","r"))freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);

#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long  b) {return (a) > (b) ? (a) : (b);}
inline long long  MAX3(long long  a, long long  b, long long  c) {return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c));}
inline long long  MIN2(long long  a, long long  b) {return (a) < (b) ? (a) : (b);}
inline long long  MIN3(long long  a, long long b, long long c) {return (a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c));}

//typedef
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;


const int mod = 1e9 + 7;
int64_t extGcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {if (!a) {x = 0; y = 1; return b;} int64_t x1, y1; int64_t d = extGcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d;}
inline ll addmod(ll a, ll b) {a = a % mod + b % mod; if (a > mod)a %= mod; return a;}
inline ll submod(ll a, ll b) {a = a % mod - b % mod; if (a < 0)a += mod; return a;}
inline ll mulmod(ll a, ll b) {return (a % mod * b % mod) % mod;}

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
inline ll exp(ll a, ll b) {if (a == 0)return 0ll; ll r = 1LL; while (b > 0) {if (b & 1) {r = r * (a % mod); r = (r + mod) % mod;} b /= 2; a = (a % mod) * (a % mod); a = (a + mod) % mod;} return (r + mod) % mod;}
ll gcd(ll a, ll b) {if (b == 0)return a; if (a == 0)return b; return gcd(b, a % b);}
uint32 setbits(ll n) {uint32 count = 0; while (n) {n &= (n - 1); count++;} return count; }
// ll f[MAX];
// ll iv[MAX];
// ll C(ll n, ll r) {
// 	if (n < r)return 0;
// 	ll ans = (f[n] % mod * iv[r] % mod) % mod;
// 	ans = (ans % mod * iv[n - r] % mod) % mod;
// 	return ans % mod;
// }
// void init() {
// 	f[0] = 1;
// 	iv[0] = 1;
// 	f(i, 1, MAX)f[i] = (i * f[i - 1]) % mod;
// 	iv[MAX - 1] = exp(f[MAX - 1], mod - 2);


// 	for (int i = MAX - 2; i >= 0; --i)iv[i] = (iv[i + 1] * (i + 1)) % mod;

// }
////****************************************************************************************************************************************************************************************************************////
vector<vector<int>>adj;
vector<vector<int>> rev;
set<int>nodes;
set<int>topo;
vector<int>indeg;
set<int> ans;
vector<bool>vis;
void kahn() {
	int n = adj.size();
	queue<int>q;
	for (int i = 0; i < n; i++) {
		if (indeg[i] == 0)q.push(i);
	}
	while (!q.empty()) {
		int curr = q.front();
		q.pop();
		topo.insert(curr);
		for (auto child : rev[curr]) {
			indeg[child]--;
			if (indeg[child] == 0)q.push(child);
		}
	}
}
void dfs(int x) {
	vis[x] = true;
	ans.insert(x);
	for (auto child : rev[x]) {
		if (vis[child] == false) {
			dfs(child);
		}
	}

}
int main() {
	tihs;
	fast_io;
	int t;
	// cin >> t;
	t = 1;
	while (t--) {
		int n, m;
		cin >> n >> m;
		adj = vector<vector<int>>(n, vector<int>());
		indeg = vector<int>(n, 0);
		vis = vector<bool>(n, false);
		rev = vector<vector<int>>(n, vector<int>());
		for (int i = 0; i < m; i++) {
			int ss, ee;
			cin >> ss >> ee;
			ss--;
			ee--;
			adj[ss].pb(ee);
			rev[ee].pb(ss);
			indeg[ss]++;
		}
		kahn();
		// for (int i = 0; i < n; i++) {
		// 	if (topo.count(i)){cout<<i<<endl;continue;}
		// 	else nodes.insert(i);
		// }
		// for (auto x : nodes)cout << x << " ";
		// cout << endl;


		// for (auto x : nodes) {
		// 	if (vis[x] == false)dfs(x);
		// }
		// 		for (auto x : ans)cout << x << " ";
		// 			cout<<endl;

		// for (auto x : ans) {
		// 	nodes.insert(x);
		// }
		// for (auto x : nodes)cout << x << " " << endl;
		cout <<n-topo.size() << endl;


	}
	return 0;
}

提出情報

提出日時
問題 F - Endless Walk
ユーザ pro_30
言語 C++ (GCC 9.2.1)
得点 500
コード長 4902 Byte
結果 AC
実行時間 225 ms
メモリ 35268 KiB

コンパイルエラー

./Main.cpp: In function ‘int main()’:
./Main.cpp:25:47: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
   25 | #define tihs if(fopen("input.txt","r"))freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
./Main.cpp:107:2: note: in expansion of macro ‘tihs’
  107 |  tihs;
      |  ^~~~
./Main.cpp:25:80: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
   25 | #define tihs if(fopen("input.txt","r"))freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
      |                                                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
./Main.cpp:107:2: note: in expansion of macro ‘tihs’
  107 |  tihs;
      |  ^~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 2
AC × 37
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, hand_17.txt, hand_18.txt, hand_19.txt, random_00.txt, 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
ケース名 結果 実行時間 メモリ
example_00.txt AC 5 ms 3544 KiB
example_01.txt AC 2 ms 3548 KiB
hand_00.txt AC 112 ms 25772 KiB
hand_01.txt AC 104 ms 25692 KiB
hand_02.txt AC 225 ms 35268 KiB
hand_03.txt AC 159 ms 30536 KiB
hand_04.txt AC 179 ms 33852 KiB
hand_05.txt AC 133 ms 29104 KiB
hand_06.txt AC 30 ms 6036 KiB
hand_07.txt AC 34 ms 6064 KiB
hand_08.txt AC 35 ms 5292 KiB
hand_09.txt AC 103 ms 29560 KiB
hand_10.txt AC 97 ms 29716 KiB
hand_11.txt AC 130 ms 29664 KiB
hand_12.txt AC 95 ms 24904 KiB
hand_13.txt AC 187 ms 32904 KiB
hand_14.txt AC 176 ms 32360 KiB
hand_15.txt AC 41 ms 22608 KiB
hand_16.txt AC 4 ms 3560 KiB
hand_17.txt AC 2 ms 3460 KiB
hand_18.txt AC 2 ms 3548 KiB
hand_19.txt AC 74 ms 20408 KiB
random_00.txt AC 35 ms 5968 KiB
random_01.txt AC 41 ms 6320 KiB
random_02.txt AC 45 ms 6768 KiB
random_03.txt AC 52 ms 7040 KiB
random_04.txt AC 88 ms 13892 KiB
random_05.txt AC 35 ms 5900 KiB
random_06.txt AC 38 ms 6288 KiB
random_07.txt AC 38 ms 6620 KiB
random_08.txt AC 51 ms 6896 KiB
random_09.txt AC 87 ms 13632 KiB
random_10.txt AC 33 ms 5664 KiB
random_11.txt AC 42 ms 6392 KiB
random_12.txt AC 46 ms 6496 KiB
random_13.txt AC 61 ms 9616 KiB
random_14.txt AC 163 ms 29132 KiB