Submission #1195304
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); --i)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 1LL * INF * INF;
const int MAX = 100100;
vector<PII> g[MAX];
int C[MAX];
pair<int,PII> Q[MAX];
int us[MAX];
int ID = 1;
int done = 0;
int n;
PII q[MAX];
int qt,qh;
void paint(int v,int d,int c)
{
if(done== n)return;
ID++;
qt=qh=0;
q[qt++]=(MP(v,d));
us[v]=ID;
if(C[v] == 0)C[v] = c,++done;
while(qh!=qt)
{
int v = q[qh].first;
int d = q[qh].second;
// cerr<<v<<" "<<d<<" "<<c<<" "<<C[v]<<endl;
++qh;
if(d==0)continue;
FOR(i,0,SZ(g[v]))
{
int to = g[v][i].first;
int ds = g[v][i].second;
if(ds>=d)continue;
if(us[to]==ID)continue;
g[v][i].second = d;
if(C[to]==0)
{
C[to]=c;
++done;
if(done == n)return;
}
us[to]=ID;
if(d==1)continue;
q[qt++]=(MP(to,d-1));
}
}
}
int main()
{
//freopen("in.txt", "r", stdin);
//ios::sync_with_stdio(false); cin.tie(0);
int m;
scanf("%d%d",&n,&m);
FOR(i,0,m)
{
int a,b;
scanf("%d%d",&a,&b);
--a;--b;
g[a].PB(MP(b,0));
g[b].PB(MP(a,0));
}
int q;
scanf("%d",&q);
FOR(i,0,q)
{
scanf("%d%d%d",&Q[i].first,&Q[i].second.first,&Q[i].second.second);
--Q[i].first;
}
RFOR(i,q,0)
{
paint(Q[i].first,Q[i].second.first,Q[i].second.second);
}
FOR(i,0,n)
{
printf("%d\n",C[i]);
}
}
Submission Info
Submission Time |
|
Task |
B - Splatter Painting |
User |
felix13 |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
1877 Byte |
Status |
AC |
Exec Time |
105 ms |
Memory |
9588 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:80:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
^
./Main.cpp:85:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&a,&b);
^
./Main.cpp:92:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&q);
^
./Main.cpp:95:69: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&Q[i].first,&Q[i].second.first,&Q[i].second.second);
^
Judge Result
Set Name |
Sample |
Subtask1 |
All |
Score / Max Score |
0 / 0 |
200 / 200 |
500 / 500 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
00_example_01.txt, 00_example_02.txt |
Subtask1 |
00_example_01.txt, 00_example_02.txt, 10_01.txt, 10_02.txt, 10_03.txt, 10_04.txt, 10_05.txt, 10_06.txt, 10_07.txt, 10_08.txt, 10_09.txt, 10_10.txt, 10_11.txt, 10_12.txt, 10_13.txt, 10_14.txt, 10_15.txt, 10_16.txt, 10_17.txt |
All |
00_example_01.txt, 00_example_02.txt, 10_01.txt, 10_02.txt, 10_03.txt, 10_04.txt, 10_05.txt, 10_06.txt, 10_07.txt, 10_08.txt, 10_09.txt, 10_10.txt, 10_11.txt, 10_12.txt, 10_13.txt, 10_14.txt, 10_15.txt, 10_16.txt, 10_17.txt, 20_01.txt, 20_02.txt, 20_03.txt, 20_04.txt, 20_05.txt, 20_06.txt, 20_07.txt, 20_08.txt, 20_09.txt, 20_10.txt, 20_11.txt, 20_12.txt, 20_13.txt, 20_14.txt, 20_15.txt, 20_16.txt |
Case Name |
Status |
Exec Time |
Memory |
00_example_01.txt |
AC |
2 ms |
3328 KB |
00_example_02.txt |
AC |
2 ms |
3328 KB |
10_01.txt |
AC |
2 ms |
3328 KB |
10_02.txt |
AC |
2 ms |
3328 KB |
10_03.txt |
AC |
2 ms |
3328 KB |
10_04.txt |
AC |
2 ms |
3328 KB |
10_05.txt |
AC |
2 ms |
3328 KB |
10_06.txt |
AC |
2 ms |
3328 KB |
10_07.txt |
AC |
2 ms |
3328 KB |
10_08.txt |
AC |
4 ms |
3456 KB |
10_09.txt |
AC |
4 ms |
3456 KB |
10_10.txt |
AC |
4 ms |
3456 KB |
10_11.txt |
AC |
4 ms |
3456 KB |
10_12.txt |
AC |
4 ms |
3456 KB |
10_13.txt |
AC |
3 ms |
3328 KB |
10_14.txt |
AC |
3 ms |
3328 KB |
10_15.txt |
AC |
3 ms |
3328 KB |
10_16.txt |
AC |
3 ms |
3456 KB |
10_17.txt |
AC |
3 ms |
3456 KB |
20_01.txt |
AC |
99 ms |
8448 KB |
20_02.txt |
AC |
105 ms |
8448 KB |
20_03.txt |
AC |
99 ms |
8448 KB |
20_04.txt |
AC |
13 ms |
4480 KB |
20_05.txt |
AC |
4 ms |
3328 KB |
20_06.txt |
AC |
10 ms |
3968 KB |
20_07.txt |
AC |
4 ms |
3328 KB |
20_08.txt |
AC |
18 ms |
4352 KB |
20_09.txt |
AC |
4 ms |
3328 KB |
20_10.txt |
AC |
18 ms |
4224 KB |
20_11.txt |
AC |
23 ms |
4352 KB |
20_12.txt |
AC |
44 ms |
7424 KB |
20_13.txt |
AC |
71 ms |
8320 KB |
20_14.txt |
AC |
76 ms |
8192 KB |
20_15.txt |
AC |
59 ms |
9460 KB |
20_16.txt |
AC |
59 ms |
9588 KB |